by Guest » 15 Jan 2025, 16:03
Ich finde ein Problem. Wenn ich eine ADO-Verbindung in C++ öffne und dann „SET QUOTED_IDENTIFIER OFF;“ aufrufe Um QUOTED_IDENTIFIER auszuschalten, kann ich eine Anweisung wie „Select „Test“;“ aufrufen.
Wenn ich jedoch ein Recordset öffne und es nicht schließe, dann rufen Sie „SET QUOTED_IDENTIFIER OFF;“ auf QUOTED_IDENTIFIER auszuschalten, wird nicht funktionieren. Rufen Sie eine Anweisung wie „Select „Test“;“ auf. wird eine Ausnahme auslösen. Warum?
Unten ist mein Beispielcode:
Code: Select all
#include
#include
#import "msado15.dll" rename("EOF", "AdoNativeEOF")
using namespace ADODB;
int main()
{
CoInitialize(NULL);
try
{
// Create ADO Connection
_ConnectionPtr pConnection;
pConnection.CreateInstance(__uuidof(Connection));
// Connection string - modify these values according to your environment
_bstr_t connStr = "Provider=SQLOLEDB;Data Source=(local);"
"Initial Catalog=MyTest;"
"Integrated Security=SSPI;";
pConnection->Open(connStr, "", "", adConnectUnspecified);
// If comment out the following statement, then "Select \"Test\";" will succeed, otherwise, it will fail.
// Open a recordset
_RecordsetPtr pRS = pConnection->Execute(
"SELECT SESSIONPROPERTY('QUOTED_IDENTIFIER')",
NULL,
adCmdText);
// Turn QUOTED_IDENTIFIER OFF
pConnection->Execute("SET QUOTED_IDENTIFIER OFF;", NULL, adCmdText | adExecuteNoRecords);
// Test
pConnection->Execute("Select \"Test\";", NULL, adCmdText | adExecuteNoRecords);
std::cout
Ich finde ein Problem. Wenn ich eine ADO-Verbindung in C++ öffne und dann „SET QUOTED_IDENTIFIER OFF;“ aufrufe Um QUOTED_IDENTIFIER auszuschalten, kann ich eine Anweisung wie „Select „Test“;“ aufrufen.
[b]Wenn ich jedoch ein Recordset öffne und es nicht schließe, dann rufen Sie „SET QUOTED_IDENTIFIER OFF;“ auf QUOTED_IDENTIFIER auszuschalten, wird nicht funktionieren. Rufen Sie eine Anweisung wie „Select „Test“;“ auf. wird eine Ausnahme auslösen. Warum?[/b]
Unten ist mein Beispielcode:
[code]#include
#include
#import "msado15.dll" rename("EOF", "AdoNativeEOF")
using namespace ADODB;
int main()
{
CoInitialize(NULL);
try
{
// Create ADO Connection
_ConnectionPtr pConnection;
pConnection.CreateInstance(__uuidof(Connection));
// Connection string - modify these values according to your environment
_bstr_t connStr = "Provider=SQLOLEDB;Data Source=(local);"
"Initial Catalog=MyTest;"
"Integrated Security=SSPI;";
pConnection->Open(connStr, "", "", adConnectUnspecified);
// If comment out the following statement, then "Select \"Test\";" will succeed, otherwise, it will fail.
// Open a recordset
_RecordsetPtr pRS = pConnection->Execute(
"SELECT SESSIONPROPERTY('QUOTED_IDENTIFIER')",
NULL,
adCmdText);
// Turn QUOTED_IDENTIFIER OFF
pConnection->Execute("SET QUOTED_IDENTIFIER OFF;", NULL, adCmdText | adExecuteNoRecords);
// Test
pConnection->Execute("Select \"Test\";", NULL, adCmdText | adExecuteNoRecords);
std::cout