在每個使用Firebird的c接口代碼的程序中,我傳遞用戶憑證以連接到數據庫。如果我不傳遞這些憑據並直接調用isc_attach_database()
來連接數據庫,則其拋出錯誤:您的用戶名和密碼未定義。要求數據庫管理員設置Firebird登錄。Firebird數據庫連接憑證
有沒有辦法跳過這些或使這些東西作爲默認。我的意思是我想連接到每個程序的數據庫,而不通過uname
和password
。
下面是我用來連接數據庫的示例代碼。
int main()
{
isc_db_handle db1 = NULL; // Database handle.
isc_tr_handle trans = NULL;//transaction handle
// Allocate some pointers to a dpb (database parameter buffer).
// You use the dpb to talk with the database.
char dpb_buffer[256], *dpb, *p;
short dpb_length;
char *uname; // user-name.
char *upass; // password.
ISC_STATUS status_vector[20]; // Status vector, to monitor connection.
char *str = "/Users/Sumanth/Desktop/NewDB2.fdb";
uname = "SYSDBA";
upass = "masterkey";
dpb = dpb_buffer;
// Specify the version of the parameter buffer, always the
// compile-time constant isc_dpb_version1.
*dpb++ = isc_dpb_version1;
// # of cache buffers to allocate for use with the database,
// default = // 75. In the API guide I think isc_dpb_num_buffers is
//specified as // isc_num_buffers, but that I could not get to work.
*dpb++ = isc_dpb_num_buffers;
*dpb++ = 1;
*dpb++ = 90;
*dpb++ = isc_dpb_user_name; // Save user-name in dpb.
*dpb++ = strlen(uname);
for (p = uname; *p;)
*dpb++ = *p++;
*dpb++ = isc_dpb_password; // Save password in dpb.
*dpb++ = strlen(upass);
for (p = upass; *p;)
*dpb++ = *p++;
dpb_length = dpb - dpb_buffer;
// Attach to the database.
isc_attach_database(status_vector, strlen(str), str, &db1,dpb_length, dpb_buffer);
}
我試圖這樣做。我在終端中設置了這些憑據。但是,當我執行代碼時,它仍然要求憑據連接到數據庫 – user3723478
@ user3723478您確定您的執行環境與您的終端共享這些環境變量嗎? –
是的,我做得對。 – user3723478