Error while executing a Ms Access db through nodejs - node.js

I am trying to access a Ms Access 2007 db trough nodejs in Windows 7, but even this simple query won't work. I receive the following message in the command prompt (this is a translation, the original is in portuguese): "Operation not allowed when object is closed". Anybody have any answers? The javascript code is written below:
var ADODB = require('node-adodb');
var connection = ADODB.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\teste\\dbteste.accdb;Persist Security Info=False;');
ADODB.debug = true;
connection
.query('SELECT * FROM [Tabela];')
.on('done', function (data){
console.log('Result:'.green.bold, data);
})
.on('fail', function (data){
});
Thanks!

Try to change the connectionString :
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\teste\\dbteste.accdb;Persist Security Info=False;
by
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\teste\\dbteste.accdb;Persist Security Info=False;
Also, check if the .accdb path is right.
Moreover, add ADODB.encoding = 'iso-8859-15'; for portuguese encoding.
I'm not sure but you may replace [Tabela] by simply Tabela. The ; at the sql query end is not necessary.

I encountered this issue too. This seems to be a bug in node-adodb module.(last seen at 8/31/2015)
In the linked page you can see that two people have encountered the same problem and the developer of node-adodb has asked them to upload the example( on 7/17/2015)

Related

Airflow: Using MySqlHook to get connection

I'm trying to get a connection object while using the MySqlHook. Assume I saved a mysql connection in the webserver admin called test_connection. What I've done:
mysql_hook = MySqlHook(conn_name_attr = 'test_connection')
conn = mysql_hook.get_conn()
Gives me an error: tuple' object has no attribute 'get_conn'
Any help would be very appreciated!
I am not sure where that code example comes from, especially the parameter conn_name_attr. It seems that the parameter is wrong.
After looking into the models and the hook itself, it seems to be
MySqlHook(mysql_conn_id='test_connection')
Also, if you get back a tuple try printing it since there might be an error message or other helpful information inside it.

pg-promise UTF connection string

pg-promise does not understand UTF passwords?.. I can't make it work with them. Tried on linux and osx, postgres 9.3, 9.5 - seems to be not specific to versions. Looked into code. pg-promise uses pg, which uses pg-connect-string which is build based on back pg. Can't find the the root of the problem. Please help.
code to reproduce:
MacBook-Air:js vao$ cat 2.js
var pgp = require("pg-promise")();
var cs = 'postgresql://utf:утф#127.0.0.1:5433/a';
var db = pgp(cs);
db.connect()
.then(function (obj) {
obj.done(); // success, release the connection;
})
.catch(function (error) {
console.log("ERROR:", error.message || error);
});
console.log(cs);
returns:
MacBook-Air:js vao$ node 2.js
postgresql://utf:утф#127.0.0.1:5433/a
ERROR: password authentication failed for user "utf"
Using same connection string with psql:
MacBook-Air:js vao$ psql 'postgresql://utf:утф#127.0.0.1:5433/a'
psql (9.5.3)
Type "help" for help.
a=> \q
Trying bad password deliberately with same connection string:
MacBook-Air:js vao$ psql 'postgresql://utf:утфWrongPassword#127.0.0.1:5433/a'
psql: FATAL: password authentication failed for user "utf"
MacBook-Air:js vao$
As the author of pg-promise, I'd like at least to offer some guidance here on where to look, not the exact answer, as I've never dealt with UTF passwords myself.
pg-promise uses node-postgres, which in turn uses pg-connection-string to parse the connection. If there is an issue, then it is most likely inside pg-connection-string.
I would recommend trying Unicode notation that relies on %. Maybe it will work. Maybe not, I've never tried. Also the following question was never answered: Node.js postgres UTF connect string, which isn't reassuring either.
Sorry, I cannot be of more help at present.

Xpages SSJS Create Administration Process

Has anyone been able to get SSJS CreateAdministrationProcess to work? I have searched for functioning code but was not able to find any.
I am trying to create an adminP request in SSJS to set a users password. I can't use the ?changepassword in the url method because we do not allow web users access to the NAB.
I am using OAUTH and when I try to hash and update the password directly to the NAB it without an adminp request, it creates problems with the current client session, logging them out and then locking them out.
I assume this is because I changed the credential tokens on the server but not on the client and when it realizes this it thinks I'm trying to authenticate over and over and locks me out.
If I can't get the SSJS to work I am going to write it in a lotusscript agent and call the agent from SSJS, but for posterity sake I wanted to get AdminP requests to work from SSJS directly.
Here is my code:
var hashednew = session.hashPassword(thenewpw)
nabDoc.replaceItemValue("HTTPPassword",hashednew)
var dt:NotesDateTime = session.createDateTime("Today 12");
nabDoc.replaceItemValue("HTTPPasswordChangeDate",dt)
dt.recycle()
var nabServerAccessView:NotesView = nabDB.getView("($ServerAccess)")
nabDB.DelayUpdates = false;
var AdminP=sessionAsSigner.CreateAdministrationProcess("abcServerName/Co")
var AdminPNoteId=AdminP.SetUserPasswordSettings(#Name("[ABBREVIATE]" ,#UserName()), 0, 0, 0, True)
nabDoc.save(true,true)
nabServerAccessView.refresh()
It is crashing at the line:
var AdminP=sessionAsSigner.CreateAdministrationProcess("abcServerName/Co")
and the server error is:
Error calling method 'CreateAdministrationProcess(string)' on an object of type 'lotus.domino.local.Session [Static Java Interface Wrapper, lotus.domino.local.Session: lotus.d
AS A FOLLOWUP,
The original code I posted had more than the uppercase/lowercase issue, in practice. I was able to get it to work, but the way I was updating to the NAB directly was wrong. I found a better way to do the password change using SSJS with the following snippet, and it's pretty simple. Of course you have to validate the old password and complexity of the new password first, but once you've done that you can run the following:
try {
var AdminP=sessionAsSignerWithFullAccess.createAdministrationProcess(server)
var chgPW=AdminP.changeHTTPPassword(theuser,theoldpw,thenewpw)
} catch(e) {print("AdminProcess configure error: " + e)}
In my opinion the problem is in naming convention - Java methods start with lower case letters.
var AdminP=sessionAsSigner.createAdministrationProcess("abcServerName/Co")
var AdminPNoteId=AdminP.setUserPasswordSettings(#Name("[ABBREVIATE]" ,#UserName()), 0, 0, 0, True)
Please check your ACL settings: Is "Maximum internet name and password" set to "Manager" or "Designer"?

NotesDXLExporter to export a database

I wrote this SSJS in a button on an XPage. I want to export the current database to a dxl file.
var stream:NotesStream = session.createStream();
var fileName:String = "c:\\Export\\exportedDB.dxl";
dBar.info(fileName,"Start Try");
try{
if(stream.open(fileName)){
dBar.info("File Opened");
stream.truncate();
dBar.info("stream Truncate");
exporter:NotesDxlExporter = session.createDxlExporter();
dBar.info("Exporter Created");
stream.writeText(exporter.exportDxl(database));
dBar.info("Export Completed");
stream.close();
dBar.info("Stream Closed")
}else{
dBar.info("Could Not Open File");
}
}catch(e){
dBar.info("try failed");
}
I get the message "Exporter Created" in the debug toolbar but the stream.write fails and goes to the "try failed". I have manager rights to the current database so I don't see it as a rights issue. According to the examples that I have been able to locate this should work. Anyone see an issue with my code?
Try adding "var" to the 1st exporter statement:
var exporter:NotesDxlExporter = session.createDxlExporter();
Even better: do this using Java. It makes it much easier to catch errors like this.
Exporting a whole database as DXL can be a little tricky. One design element with a problem and your whole export fails. So this is nothing you can 100% rely on.
I learned that lesson the hard way when I wrote DXLMagic (source is on OpenNTF). Dxl handling has gotten better with later Notes versions, but isn't "end-user ready"
I would for starters follow Per's suggestion and do this in Java. Secondly, reuse the code of DXLMagic. There I export one element after the other (and stitch it into one result) to avoid failure if one element isn't clean.
Dxl isn't very good with XPages stuff and you might be better off using an OnDisk project (code only and requires a designer on the other end)

subsonic 3.0 how to correctly close connection?

I'm using Subsonic 3.0.0.3 Active Directory.
During program work, opens many connections to MySQL data base. I can see this threads in MySQL Administrator.
I'm working with data base in this case:
var db = new DB();
var nClient = Enumerable.First(db.clients, c => c.id_client == cl.ID);
nClient.data = data;
nClient.Update();
another example
var nClient = new client { data= cl.data };
nClient.Save();
How should I correctly close connection to database? Or how to use only one connection to database?
It will close the connection straight way. SubSonic was designed to only open the connection when needed and close when finished.
If you want to use the same connection for several queries you need to look in to the batch query

Resources