Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

c++ - How to use SQLConnect or SQLDriverConnect

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 is something like 111.111.111.111,9999

EDIT: 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);

But now I get this error HY024 - Invalid attribute value

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...