gpt4 book ai didi

c - Firebird 数据库连接凭据

转载 作者:太空宇宙 更新时间:2023-11-04 03:46:18 25 4
gpt4 key购买 nike

在使用 Firebird 的每个 C 接口(interface)代码程序中,我都传递用户凭据以连接到数据库。如果我不传递这些凭据并直接调用 isc_attach_database() 连接到数据库,它会抛出错误:您的用户名和密码未定义。请您的数据库管理员设置 Firebird 登录。

有没有办法跳过这些或将这些设置为默认设置。我的意思是我想为每个程序连接到数据库而不传递 unamepassword

下面是我用来连接数据库的示例代码。

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);
}

最佳答案

您可以设置环境变量 ISC_USERISC_PASSWORD 以连接到 Firebird 数据库,而无需在应用程序中指定用户名和密码。参见 Setting The ISC_USER And ISC_PASSWORD Environment Variables .请注意,链接文档仅讨论 SYSDBA 帐户,但它适用于任何帐户。

Helen Borrie 的 The Firebird Book,第 2 版说:

It is possible to set up the two environment variables ISC_USER and ISC_PASSWORD on the server, to avoid the need to log in when working with databases locally. You will be able do everything that the named user is allowed to do, without needing to supply credentials each time.

文中提到“在服务器上”,但它实际上是客户端应用程序本地的。

Interbase 6.0 操作指南(可从 Firebird website 获得)说:

If you do not provide a user name and password when you connect to a database or whenyou run utilities such as gbak, gstat, and gfix, InterBase looks to see if the ISC_USER and ISC_PASSWORD environment variables are set and uses that user and password as the InterBase user.

Although setting these environment variables is convenient, it is strongly notrecommended if security is at all an issue.

关于c - Firebird 数据库连接凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24147048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com