任意の入力をいただければ幸いです。ODBC&Node.jsを使用してデータを挿入する
私は、ODBC接続文字列を使用して、node.jsを使用してSQLデータベースに接続しています。私は正常に接続を確立し、データベースを照会することができますが、データを挿入しようとすると問題が発生します。
ODBCプラグインはここで見つけることができます:ここでhttps://www.npmjs.com/package/odbc
は私が再作成しようとしている例です。ここで
var db = require("odbc")()
, cn = "DRIVER={FreeTDS};SERVER=host;UID=user;PWD=password;DATABASE=dbname"
;
//Blocks until the connection is open
db.openSync(cn);
db.prepare("insert into hits (col1, col2) VALUES (?, ?)", function (err, stmt) {
if (err) {
//could not prepare for some reason
console.log(err);
return db.closeSync();
}
//Bind and Execute the statment asynchronously
stmt.execute(['something', 42], function (err, result) {
result.closeSync();
//Close the connection
db.closeSync();
});
})
は私のコードです:
var db = require("odbc")()
, cn = "Driver={ODBC Driver 13 for SQL Server};Server=host:insert-name.database.windows.net,insert-port;Database=insert-database-name;Uid=insert-uid;Pwd=insert-password;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
;
//Blocks until the connection is open
//Blocks until the connection is open
db.openSync(cn);
//Blocks while preparing the statement
db.prepare("INSERT INTO Contact (FirstName, LastName, Country, User, Email, PrivacyAgreement, PhoneNumber) VALUES (?,?,?,?,?,?,?)", function (err, stmt) {
if (err) {
//could not prepare for some reason
console.log(err);
return db.closeSync();
}
console.log(stmt);
//Bind and Execute the statment asynchronously
stmt.execute(['first','last','country_name', 1, '[email protected]', 1, '9999999999'], function (err, result) {
result.closeSync();
console.log(result);
//Close the connection
db.closeSync();
});
})
注: ' User 'と' PrivacyAgreement 'はビットデータ型(ブール値)で、残りはvarcharです。
れ、私は次のエラーを取得するには、次のstmt.execute
によって返さ未定義