这是我的源代码示例,其灵感来自Firebird安装目录(C:\ Program Files \ Firebird \ Firebird_2_5 \ examples)中的代码示例:
AnsiString db_path = MainForm->exeFilePath + "\\results.fdb"; // C:\Projects\DBX\bin\results.fdb
if (FileExists(db_path))
{
return;
}
HMODULE dll = LoadLibrary(L"fbclient.dll");
if (dll == NULL)
{
throw Exception(L"Failed to load Firebird client library FBCLIENT.DLL!\r\nApplication will exit now.");
}
Pisc_dsql_execute_immediate pisc_dsql_execute_immediate = (Pisc_dsql_execute_immediate)GetProcAddress(dll, "isc_dsql_execute_immediate");
if (pisc_dsql_execute_immediate == NULL)
{
throw Exception(L"Failed to load 'isc_dsql_execute_immediate' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
Pisc_commit_transaction pisc_commit_transaction = (Pisc_commit_transaction)GetProcAddress(dll, "isc_commit_transaction");
if (pisc_commit_transaction == NULL)
{
throw Exception(L"Failed to load 'isc_commit_transaction' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
Pisc_detach_database pisc_detach_database = (Pisc_detach_database)GetProcAddress(dll, "isc_detach_database");
if (pisc_detach_database == NULL)
{
throw Exception(L"Failed to load 'isc_detach_database' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
Pisc_sqlcode pisc_sqlcode = (Pisc_sqlcode)GetProcAddress(dll, "isc_sqlcode");
if (pisc_sqlcode == NULL)
{
throw Exception(L"Failed to load 'isc_sqlcode' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
ISC_STATUS_ARRAY status; /* status vector */
isc_db_handle newdb = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
AnsiString create_db;
create_db.printf("CREATE DATABASE '%s'", db_path.c_str());
long sqlcode;
UnicodeString msg;
if (pisc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db.c_str(), 1, NULL))
{
// ERROR OCCURRES HERE
sqlcode = pisc_sqlcode(status);
msg.printf(L"Operation 'CREATE DATABASE' failed with sqlcode %ld.\r\nApplication will exit now.", sqlcode);
throw Exception(msg.c_str());
}
pisc_commit_transaction(status, &trans);
pisc_detach_database(status, &newdb);
FreeLibrary(dll);
dll = NULL;
使用sql代码-902创建数据库失败。目录“C:\ Projects \ DBX \ bin \”存在且不包含名为“results.fdb”的文件。什么是错误行为的原因,我怎么能避免它?是否有Firebird API的详细描述?
答案 0 :(得分:0)
我忘了的是用户凭据。请参阅更新的代码示例(摘录):
ISC_STATUS_ARRAY status; /* status vector */
isc_db_handle newdb = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
AnsiString create_db;
create_db.printf("CREATE DATABASE '%s' USER '%S' PASSWORD '%S'", db_path.c_str(), MainForm->currentUser.name, MainForm->currentUser.password);
long sqlcode;
UnicodeString msg;
if (pisc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db.c_str(), 1, NULL))
{
sqlcode = pisc_sqlcode(status);
msg.printf(L"Operation 'CREATE DATABASE' failed with sqlcode %ld.\r\nApplication will exit now.", sqlcode);
throw Exception(msg.c_str());
}