OLE DB, OleDbConnection (Access)
密码连接:
CODE:
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;
Password=myPassword;
window身份认证:
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;
Integrated Security=SSPI;
Use serverName/instanceName as Data Source to use a specific SQL Server instance. Please note that the multiple SQL Server instances feature is available only from SQL Server version 2000 and not in any previous versions.
IP 地址连接:
CODE:
Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;
Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;DBMSSOCN=TCP/IP
This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.
Prompt for username and password:
oConn.Provider = "sqloledb"
oConn.Properties("rompt") = adPromptAlways
Data Source=myServerAddress;Initial Catalog=myDataBase;This one is a bit tricky. First set the connection object's Provider property to "sqloledb". Thereafter set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database. SqlConnection(SqlServer)
密码连接:
1、
CODE:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;
Password=myPassword;2、
Server=myServerAddress;Database=myDataBase;User ID=myUsername;
Password=myPassword;Trusted_Connection=False;
This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
window身份认证:
1、CODE: Data Source=myServerAddress;Initial Catalog=myDataBase;
Integrated Security=SSPI;2、
Server=myServerAddress;Database=myDataBase;
Trusted_Connection=True;
Use serverName/instanceName as Data Source to use a specific SQL Server instance. Please note that the multiple SQL Server instances feature is available only from SQL Server version 2000 and not in any previous versions.
IP地址连接:
CODE: Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;
Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Specifying packet size:
Server=myServerAddress;Database=myDataBase;User ID=myUsername;
Password=myPassword;Trusted_Connection=False;Packet Size=4096;
By default, the Microsoft .NET Framework Data Provider for SQL Server sets the network packet size to 8192 bytes. This might however not be optimal, try to set this value to 4096 instead.