如何使用SQLConnect或SQLDriverConnect [英] How to use SQLConnect or SQLDriverConnect

查看:2758
本文介绍了如何使用SQLConnect或SQLDriverConnect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试连接到互联网上的MS-SQL服务器。我应该对SQLConnect的ServerName参数放什么?

I am trying to connect to a MS-SQL server on the internet. What should I put on the ServerName parameter of SQLConnect?

我试过了,但是失败了:

I've tried this, but it fails:

"DRIVER=SQL Server;SERVER=SERVER_IP;DATABASE=sales"

SERVER_IP类似于111.111.111.111,9999

SERVER_IP is something like 111.111.111.111,9999

编辑:
我遵循Johns的建议,这里是我当前的代码:

I followed Johns advice and here is my current code:

SQLCHAR OutConnStr[255];
SQLSMALLINT OutConnStrLen;
SQLTCHAR *srv = (SQLTCHAR *)"Provider=SQLOLEDB.1;Password=pw;Persist Security Info=True;User ID=me;Initial Catalog=mydb;Data Source=1.2.3.4,9999";
rc = SQLDriverConnect(conn_h, NULL, srv, strlen((char*)srv), OutConnStr, 255, &OutConnStrLen, SQL_DRIVER_PROMPT);

但现在我得到这个错误HY024 - 属性值无效

But now I get this error HY024 - Invalid attribute value

推荐答案

这里是一个SQL Server连接字符串的技巧。在桌面上创建一个名为test.udl的文件。一旦创建,双击并打开文件。将提示您设置数据库连接。根据需要配置连接。完成后,测试连接。最后关闭向导。然后右键单击test.udl文件并用记事本打开。您将看到您创建的连接字符串。

Here is a trick with SQL Server Connection Strings. Create a file on you desktop called test.udl. Once created, double click and open the file. You will be prompted to set up the Database Connection. Configure the connection as needed. When Finished, test the connection. Finally close the wizard. Then right click the test.udl file and open with notepad. You will see the connection string you created.

这篇关于如何使用SQLConnect或SQLDriverConnect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆