在运行时创建数据库并在运行时将其注册为 DSN
我正在尝试在运行时创建 ACCESS DB,并使用以下代码在 ODBC.ini 中注册为 DSN:
BOOL fCreated;
fCreated = SQLConfigDataSource(NULL,ODBC_ADD_DSN,
"Microsoft Access Driver (*.mdb)",
"CREATE_DB=.\\ATest.mdb General\0" );
printf("Database created : %d\n",fCreated);
BOOL ReturnResult = SQLConfigDataSource (NULL, ODBC_CONFIG_DSN,
"Microsoft Access Driver (*.mdb)",
"DSN=TESTDSN_DSN\00DBQ=.\\ATest.mdb\ \
00FIL=MSAccess\00Description=TESTDSN_database\00UID=\00");
printf("Database registered : %d\n",ReturnResult);
第一个语句返回 1,表明数据库已创建,但第二个语句返回 0,表明无法注册作为 ODBC.ini 中的 DataSourceName。谁能告诉我为什么会发生这种情况,因为路径和名称等所有内容都是正确的。
I am trying to create an ACCESS DB at run time and register is as a DSN in ODBC.ini using the following code:
BOOL fCreated;
fCreated = SQLConfigDataSource(NULL,ODBC_ADD_DSN,
"Microsoft Access Driver (*.mdb)",
"CREATE_DB=.\\ATest.mdb General\0" );
printf("Database created : %d\n",fCreated);
BOOL ReturnResult = SQLConfigDataSource (NULL, ODBC_CONFIG_DSN,
"Microsoft Access Driver (*.mdb)",
"DSN=TESTDSN_DSN\00DBQ=.\\ATest.mdb\ \
00FIL=MSAccess\00Description=TESTDSN_database\00UID=\00");
printf("Database registered : %d\n",ReturnResult);
The first statement returns 1 showing that the DB is created but the second one returns 0 indicating that it could not be registered as a DataSourceName in ODBC.ini. Can anyone please tell me why is this happening because everything like path and name is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在问题的评论中已经提到了这一点,但我想提供一个包含更多信息的答案:
与其在某些机器上通过代码创建 DSN,不如在客户端中链接无 DSN(以编程方式)的表可能更容易这将访问数据库。
如果客户端也是 MS Access,则可以使用
DoCmd 来完成此操作。传输数据库
:It was already mentioned in the comments to the question, but I wanted to provide an answer with some more information:
Instead of creating a DSN by code on some machine, it's probably easier to link the tables DSN-less (programmatically) in the client that will access the database.
If the client is MS Access as well, you can do it with
DoCmd.TransferDatabase
: