|
在MSDN中,.net的数据库连接字符串都有详细的说明,本文以代码范例的方式罗列一些,具体的每一项代表的意义可以参看MSDN. ADO.net 中数据库连接方式(微软提供) 微软提供供了以下四种数据库连接方式: System.Data.SqlClient.SqlConnection SqlConnection conn = new SqlConnection("Server=(local);Integrated Security=SSPI;database=Pubs");SqlConnection conn = new SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI");SqlConnection conn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");SqlConnection conn = new SqlConnection(" data source=(local);initial catalog=xr;integrated security=SSPI;persist security info=False;workstation id=XURUI;packet size=4096; ");SqlConnection myConn = new System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer");SqlConnection conn = new SqlConnection( " uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1;Connect Timeout=900");System.Data.OleDb.OleDbConnection OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyWeb\81\05\GrocerToGo.mdb");OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=grocertogo.mdb;"); OleDbConnection conn = new OleDbConnection("Provider=MSDAORA; Data Source=ORACLE8i7;Persist Security Info=False;Integrated Security=yes"); OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\bin\LocalAccess40.mdb");OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB;Data Source=MySQLServer;Integrated Security=SSPI");System.Data.OracleClient.OracleConnection OracleConnection myConn = new System.Data.OracleClient.OracleConnection("Data Source=Oracle8i;Integrated Security=yes");System.Data.Odbc.OdbcConnection OdbcConnection conn = new OdbcConnection("Driver={SQL Server};Server=MyServer;Trusted_Connection=yes;Database=Northwind;");OdbcConnection conn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;Persist Security Info=False;Trusted_Connection=yes");OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\nwind.mdb");OdbcConnection conn = new OdbcConnection("Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls");OdbcConnection conn = new OdbcConnection("Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin");OdbcConnection conn = new OdbcConnection("DSN=dsnname");其他厂商提供的数据库连接: DB2Connection myConn = new IBM.Data.DB2.DB2Connection("DATABASE = SAMPLE;UID=; PWD=;");DB2Connection myConn = new IBM.Data.DB2.DB2Connection("DATABASE = SAMPLE"); BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borland.Data.Mssql,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;vendorclient=sqloledb.dll;osauthentication=False;database=;username=;hostname=;password=;provider=MSSQL");BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borland.Data.Db2,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;vendorclient=db2cli.dll;database=;username=;password=;provider=DB2");Connection Pooling |