SQL Server
JDBC
jTDS
Class.forName("net.sourceforge.jtds.jdbc.Driver ");
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");
点击此处下载jtds jdbc驱动
SQL Server 2000 Driver for JDBC
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://server1:1433","user","password");
点击此处下载microsoft sqlserver jdbc驱动
ODBC
Standard Security
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Trusted connection
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;
Prompt for username and password
oConn.Properties("Prompt") = adPromptAlways
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;
(注意:这个连接串需要在连接前设定Prompt属性,然后才能连接 )
原文解释:This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
OLE DB, OleDbConnection (.NET)
Standard Security
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Trusted connection
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
(注意:数据源使用服务器名/实例名 只能在sql server2000版本中,早先的版本是不用的 )
原文解释: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.
Prompt for username and password
oConn.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways
Data Source=myServerAddress;Initial Catalog=myDataBase;
(注意:连接前先要设置Provider 和 prompt )
原文解释: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.
Connect via an IP address
Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
(DBMSSOCN=TCP/IP , 使用tcp/ip代替命名通道。默认端口为1433)
原文解释: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.
SqlConnection (.NET)
Standard Security
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Standard Security alternative syntax
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.
Trusted Connection
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Trusted Connection alternative syntax
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
(注意:这个连接串和上面那个是一样的,因为他们的参数是等价的 )
原文解释: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.
Connect via an IP address
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;
(注意:.net默认设置Packet Size为8192.最佳的设置最好为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.
Data Shape
MS Data Shape
Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
JDBC
jTDS
Class.forName("net.sourceforge.jtds.jdbc.Driver ");
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");
点击此处下载jtds jdbc驱动
SQL Server 2000 Driver for JDBC
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://server1:1433","user","password");
点击此处下载microsoft sqlserver jdbc驱动
ODBC
Standard Security
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Trusted connection
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;
Prompt for username and password
oConn.Properties("Prompt") = adPromptAlways
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;
(注意:这个连接串需要在连接前设定Prompt属性,然后才能连接 )
原文解释:This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
OLE DB, OleDbConnection (.NET)
Standard Security
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Trusted connection
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
(注意:数据源使用服务器名/实例名 只能在sql server2000版本中,早先的版本是不用的 )
原文解释: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.
Prompt for username and password
oConn.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways
Data Source=myServerAddress;Initial Catalog=myDataBase;
(注意:连接前先要设置Provider 和 prompt )
原文解释: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.
Connect via an IP address
Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
(DBMSSOCN=TCP/IP , 使用tcp/ip代替命名通道。默认端口为1433)
原文解释: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.
SqlConnection (.NET)
Standard Security
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Standard Security alternative syntax
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.
Trusted Connection
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Trusted Connection alternative syntax
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
(注意:这个连接串和上面那个是一样的,因为他们的参数是等价的 )
原文解释: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.
Connect via an IP address
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;
(注意:.net默认设置Packet Size为8192.最佳的设置最好为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.
Data Shape
MS Data Shape
Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
