使用ODBC访问远程SQL的问题
我想在程序中根据用户输入的IP地址和帐号密码来动态的设置数据源,然后再和远程SQL主机建立连接,比如远程SQL主机为111.111.111.111:1433,帐号为sa,密码为123456,这样的话我该在SQLConfigDataSource这条API中怎么设置他的参数来实现动态创建数据源呢?
谢谢各位高手了.
[解决办法]
代码大概这样:
char szAttributes[128];
memset(szAttributes, '\0 ',128);
char * p=szAttributes;
strcpy(p, "DSN=xxxxxName ");//!!!
p=p+strlen(p)+1;
strcpy(p, "SERVER= ");
strcat(p,strIP);//111.111.111.111
p=p+strlen(p)+1;
strcpy(p, "ADDRESS= ");
strcat(p,strIP);
strcat(p, ",1433 ");
p=p+strlen(p)+1;
strcpy(p, "NETWORK=dbmssocn ");
p=p+strlen(p)+1;
strcpy(p, "DATABASE=xxxDB ");//默认数据库
SQLConfigDataSource(NULL,
ODBC_ADD_SYS_DSN,
"SQL Server ",
szAttributes);