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 ";
(contains 6 entries, with user name and password, database name, server name (server name can be on the network, at this time is an IP address))
Second connection string to connect SQL Server:
For the authentication mode is Windows only,
The connection string is:
Strconn= "
Provider = sqloledb.1;\
Integrated security=sspi;\
Persist Security Info =false;\
Initial Catalog = tempdb;\
Data Source = (local) ";
(contains 5 items, because Windows is already authenticated, so no longer requires a username and password, and if it is a native SQL Server, the server name can be written as (local))
Third, the second connection string to connect to SQL Server:
For ODBC-only connection methods,
The connection string is:
Strconn= "
Provider = sqloledb;\
Server = (local); \
Database = tempdb;\
UID = sa;\
pwd=12345; "
Above three kinds of connection way, remember any one can, recommend the use of the second
About the connection string problem, we can use the UDL file to deal with ~ ~
Create a new empty TXT file. Change the extension to UDL.
The UDL itself is a text file.
Its primary role is to view the configured database connection words. Configure it first. Then use Notepad to open
Eg: we create a test.udl file on the desktop,
1. If you are connecting to a SQL Server database, the provider selection:
Microsoft OLE DB Provider for SQL Server,