Vc_ado connection string mode when connecting to SQL Server

Source: Internet
Author: User
Tags sql server connection string ole

One, the first connection string to connect to SQL Server:

is for SQL SERVER and Windows for the database authentication mode,

The connection string is:

CString strconn;

strconn = "Provider = sqloledb.1;\

Persist Security Info = true;\

User ID = sa;\

Password=123456;\

Initial Catalog = tempdb;\

Data Source = 127.0.0.1 ";

(including 6 items, real username and password, database name.) Server name (the server name can be on the network, and this is an IP address))


Two, another connection string that connects to SQL Server:

For the authentication mode "Windows only",

The connection string is:

Strconn= "

Provider = sqloledb.1;\

Integrated security=sspi;\

Persist Security Info =false;\

Initial Catalog = tempdb;\

Data Source = (local) ";

(includes 5 items, because Windows verified already.) So no longer need username and password. If it is a native SQL Server, then the server name can be written as (local))


Third, another connection string that connects to SQL Server:

ODBC-only Connection mode,

The connection string is:

Strconn= "

Provider = sqloledb;\

Server = (local); \

Database = tempdb;\

UID = sa;\

pwd=12345; "


The above three kinds of connection methods, remember the arbitrary one can. It is recommended to use a different


regarding the connection string problem, we can use the UDL file to process ~ ~

Create a new empty TXT file. You can change the extension to a UDL. The UDL itself is a text file. Its main function is to view the configured database connection Word. Configure it first. Then use Notepad to open

eg: we create a test.udl file on the desktop,

1. Assuming that you want to connect to the SQL Server database, the provider chooses:

Microsoft OLE DB Provider for SQL Server,

2. "Connection", the server name, select Richardlee (that is, the native server name)

Let's say we choose Windows Authentication mode, we don't have to specify username and password.

The "Select database on Server" column. Just fill in the database that we want to connect to in SQL Server. For example, test

Then click on "Test Connection". Suppose the connection succeeds. That means our connection strings are all right.

3. (We fill in the connection string, in the "All" this column can be seen)

4. Change the suffix name of the file to *.txt when it is opened. will be able to find the connection string. eg

[OLE DB]
; Everything after the "is" an OLE DB initstring
Provider=sqloledb.1;integrated Security=sspi; Persist Security info=false;initial Catalog=test1;data Source=richardlee

5. The above connection string can be used in our program, for example

hr = M_pconnection.createinstance (__uuidof (Connection));

hr = M_pconnection->open ("provider=sqloledb.1;\
Integrated security=sspi;\
Persist Security info=false;\
Initial catalog=test1;\
Data source= (local) "," "," ", adModeUnknown);


(PS: In the connection string.) The order of the parts has no effect on the database connection, that is, integrated security and persist security Info, who is in front of who in the post, it doesn't matter)


*************************************************************************************************************** *********

Vc_ado connect to SQL Server connection string and Vc-ado connection string for access there are some different places ~ ~

1. When you connect to access, you often use

hr = M_pconnection->open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test1.mdb", "" "," ", AdModeUnknown);

That is, the connection string is "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test1.mdb"

The data Source=d:\\test1.mdb here is the name of the Access database, unless the database file is placed under the current project path. Otherwise write all path names, and write the suffix of the database

Be aware that it is "d:\\", not "d:\", which is written in the latter. Will go wrong

2. When you connect to SQL Server,

Initial Catalog=test1; This represents the database name of the connection, and it is important to note that the test1 here is the name of the database. You can't add a path to him or add a suffix *.mdf. Written

Initial catalog=d:\program Files\Microsoft SQL Server\mssql10. The mssqlserver\mssql\data\test1.mdf will make a mistake.




Vc_ado connection string mode when connecting to SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.