




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、数据库连接字符串大全转自:SQL Server ODBC Standard Security:Driver=SQL Server;Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;Trusted connection:Driver=SQL Server;Server=Aron1;Database=pubs;Trusted_Connection=yes;PRompt for username and passWord:oConn.Properties(Prompt)=adPromptAlways oConn.OpenDriver=SQL Server;Se
2、rver=Aron1;DataBase=pubs;OLE DB,OleDbConnection(.NET)Standard Security:Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;Trusted Connection:Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;(use serverNameinstanceName as Data Source t
3、o use an specifik SQLServer instance,only SQLServer2000)Prompt for username and password:oConn.Provider=sqloledboConn.Properties(Prompt)=adPromptAlways oConn.OpenData Source=Aron1;Initial Catalog=pubs;Connect via an ip address:Provider=sqloledb;Data Source=00,1433;Network Library=DBMSSO
4、CN;Initial Catalog=pubs;User ID=sa;Password=asdasd;(DBMSSOCN=TCP/IP instead of Named Pipes,at the end of the Data Source is the port to use(1433 is the default)SqlConnection(.NET)Standard Security:Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;-or-Server=Aron1;Database=pubs;User I
5、D=sa;Password=asdasd;Trusted_Connection=False(both connection strings produces the same result)Trusted Connection:Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;-or-Server=Aron1;Database=pubs;Trusted_Connection=True;(both connection strings produces the same result)(use serverNamein
6、stanceName as Data Source to use an specifik SQLServer instance,only SQLServer2000)Connect via an IP address:Data Source=00,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;(DBMSSOCN=TCP/IP instead of Named Pipes,at the end of the Data Source is the port to
7、use(1433 is the default)Declare the SqlConnection:C#:using System.Data.SqlClient;SqlConnection oSQLConn=new SqlConnection();oSQLConn.ConnectionString=my connection string;oSQLConn.Open();VB.NET:Imports System.Data.SqlClient Dim oSQLConn As SqlConnection=New SqlConnection()oSQLConn.ConnectionString=m
8、y connection stringoSQLConn.Open()Data Shape MS Data ShapeProvider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User ID=sa;Password=asdasd;Want to learn data shaping?Check out 4GuyfFromRollas great article about Data Shaping Read more How to define which network protocol
9、 to use Example:Provider=sqloledb;Data Source=00,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;Name Network library dbnmpntw Win32 Named Pipes dbmssocn Win32 Winsock TCP/IP dbmsspxn Win32 SPX/IPX dbmsvinn Win32 Banyan Vines dbmsrpcn Win32 Multi-Protocol(W
10、indows RPC)Important note!When connecting through the SQLOLEDB provider use the syntax Network Library=dbmssocn and when connecting through MSDASQL provider use the syntax Network=dbmssocn All SqlConnection connection string properties This table shows all connection string properties for the ADO.NE
11、T SqlConnection object.Most of the properties are also used in ADO.All properties and descriptions is from msdn.Name Default Description application Name The name of the application,or.Net SqlClient Data Providerif no application name is provided.AttachDBFilename-or-extended properties-or-Initial Fi
12、le Name The name of the primary file,including the full path name,of an attachable database.The database name must be specified with the keyworddatabase.Connect Timeout-or-Connection Timeout 15 The length of time(in seconds)to wait for aconnection to the server before terminating the attempt and gen
13、erating an error.Connection Lifetime 0When aconnection is returned to the pool,its creation time is com pared with the current time,and the connection is destroyed if that time span(in seconds)exceeds the value specified by connection lifetime.Useful in clustered configurations to force load balanci
14、ng between arunning server and aserver just brought on-line.Connection ResettrueDetermines whether the database connection is reset when being removed from the pool.Setting tofalseavoids making an additional server round-trip when obtaining aconnection,but the programmer must be aware that the conne
15、ction state is not being reset.Current Language The SQL Server Language record name.Data Source-or-Server-or-Address-or-Addr-or-Network Address The name or network address of the instance of SQL Server to which to connect.EnlisttrueWhen true,the pooler automatically enlists the connection in the cre
16、ation threads current transaction context.Initial Catalog-or-Database The name of the database.Integrated Security-or-Trusted_ConnectionfalseWhether the connection is to be asecure connection or not.Recognized values aretrue,false,andsspi,which is equivalent totrue.Max Pool Size 100 The maximum numb
17、er of connections allowed in the pool.Min Pool Size 0The minimum number of connections allowed in the pool.Network Library-or-NetdbmssocnThe network library used to establish aconnection to an instance of SQL Server.Supported values include dbnmpntw(Named Pipes),dbmsrpcn(Multiprotocol),dbmsadsn(Appl
18、e Talk),dbmsgnet(VIA),dbmsipcn(Shared Memory)and dbmsspxn(IPX/SPX),and dbmssocn(TCP/IP).The corresponding network DLL must be installed on the system to which you connect.If you do not specify anetwork and you use alocal server(for example,.or(local),shared memory is used.Packet Size 8192 Size in by
19、tes of the network packets used to communicate with an instance of SQL Server.Password-or-Pwd The password for the SQL Server account logging on.Persist Security InfofalseWhen set tofalse,security-sensitive inf ormation,such as the password,is not returned as part of the connection if the connection
20、 is open or has ever been in an open state.Resetting the connection string resets all connection string values including the password.PoolingtrueWhen true,the SQLConnection object is drawn from the appropriate pool,or if necessary,is created and added to the appropriate pool.User ID The SQL Server l
21、ogin account.Workstation ID the local computer name The name of the workstation connecting to SQL Server.Note Use;to separate each property.If aname occurs more than once,the value from the last one in the connection string will be used.If you are building your connection string in your app using va
22、lues from user input fields,make sure the user cant change the connection string by inserting an additional property with another value within the user value.SQL Server 2005 SQL Native Client ODBC Driver Standard security:Driver=SQL Native Client;Server=Aron1;Database=pubs;UID=sa;PWD=asdasd;Trusted
23、connection:Driver=SQL Native Client;Server=Aron1;Database=pubs;Trusted_Connection=yes;Equivalents Integrated Security=SSPI equals Trusted_Connection=yes Prompt for username and password:oConn.Properties(Prompt)=adPromptAlways oConn.OpenDriver=SQL Native Client;Server=Aron1;DataBase=pubs;Enabling MAR
24、S(multiple active result sets):Driver=SQL Native Client;Server=Aron1;Database=pubs;Trusted_Connection=yes;MARS_Connection=yesEquivalents MultipleActiveResultSets=true equals MARS_Connection=yes Using MARS with SQL Native Client,by Chris Lee Encrypt data sent over network:Driver=SQL Native Client;Ser
25、ver=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yesAttach adatabase file on connect to alocal SQL Server Express instance:Driver=SQL Native Client;Server=.SQLExpress;AttachDbFilename=c:asdqwemydbfile.mdf;Database=dbname;Trusted_Connection=Yes;-or-Driver=SQL Native Client;Server=.SQLExpress;At
26、tachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;(use|DataDirectory|when your database file resides in the data directory)Why is theDatabaseparameter needed?Answer:If the database was previously attached,SQL Server does not reattach it(it uses the attached database a
27、s the default for the connection).Download the SQL Native Client here(the package contains booth the ODBC driver and the OLE DB provider)Using SQL Server 2005 Express?Dont miss the server name syntax:SERVERNAMESQLEXPRESS(SubstituteSERVERNAMEwith the name of the computer)SQL Native Client OLE DB Prov
28、ider Standard security:Provider=SQLNCLI;Server=Aron1;Database=pubs;UID=sa;PWD=asdasd;Trusted connection:Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;Equivalents Integrated Security=SSPI equals Trusted_Connection=yes Prompt for username and password:oConn.Properties(Prompt)=adPr
29、omptAlways oConn.OpenProvider=SQLNCLI;Server=Aron1;DataBase=pubs;Enabling MARS(multiple active result sets):Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;MarsConn=yesEquivalents MarsConn=yes equals MultipleActiveResultSets=true equals MARS_Connection=yes Using MARS with SQL Nati
30、ve Client,by Chris Lee Encrypt data sent over network:Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yesAttach adatabase file on connect to alocal SQL Server Express instance:Provider=SQLNCLI;Server=.SQLExpress;AttachDbFilename=c:asdqwemydbfile.mdf;Database=dbname;Trusted
31、_Connection=Yes;-or-Provider=SQLNCLI;Server=.SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;(use|DataDirectory|when your database file resides in the data directory)Why is theDatabaseparameter needed?Answer:If the database was previously attached,SQL S
32、erver does not reattach it(it uses the attached database as the default for the connection).Download the SQL Native Client here(the package contains booth the ODBC driver and the OLE DB provider)Using SQL Server 2005 Express?Dont miss the server name syntax:SERVERNAMESQLEXPRESS(SubstituteSERVERNAMEw
33、ith the name of the computer)SqlConnection(.NET)Standard Security:Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;-or-Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False(both connection strings produces the same result)Trusted Connection:Data Source=Aron1
34、;Initial Catalog=pubs;Integrated Security=SSPI;-or-Server=Aron1;Database=pubs;Trusted_Connection=True;(both connection strings produces the same result)(use serverNameinstanceName as Data Source to use an specifik SQLServer instance)Connect via an IP address:Data Source=00,1433;Network
35、Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;(DBMSSOCN=TCP/IP instead of Named Pipes,at the end of the Data Source is the port to use(1433 is the default)Enabling MARS(multiple active result sets):Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=trueNot
36、e!Use ADO.NET 2.0 for MARS functionality.MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1 Streamline your Data Connections by Moving to MARS,by Laurence Moroney,DevX.com Attach adatabase file on connect to alocal SQL Server Express instance:Server=.SQLExpress;AttachDbFilename=c:asdqwemydbfile.md
37、f;Database=dbname;Database=dbname;Trusted_Connection=Yes;-or-Server=.SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;(use|DataDirectory|when your database file resides in the data directory)Why is theDatabaseparameter needed?Answer:If the database was p
38、reviously attached,SQL Server does not reattach it(it uses the attached database as the default for the connection).UsingUser Instanceon alocal SQL Server Express instance:Data Source=.SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|mydb.mdf;user instance=true;TheUser Instancefun
39、ctionality creates anew SQL Server instance on the fly during connect.This works only on alocal SQL Server 2005 instance and only when connecting using windows authentication over local named pipes.The purpose is to be able to create afull rights SQL Server instance to auser with limited administrat
40、ive rights on the computer.To enable the functionality:sp_configureuser instances enabled,1(0 to disable)Using SQL Server 2005 Express?Dont miss the server name syntax:SERVERNAMESQLEXPRESS(SubstituteSERVERNAMEwith the name of the computer)Context Connection-connecting toselffrom within your CLR stor
41、ed prodedure/function C#:using(SqlConnection connection=new SqlConnection(context connection=true)connection.Open();/Use the connectionVisual Basic:Using connection as new SqlConnection(context connection=true)connection.Open()Use the connection End Using The context connection lets you execute Tran
42、sact-SQL statements in the same context(connection)that your code was invoked in the first place.Read more When to use SQL Native Client?.Net applications Do not use the SQL Native Client.Use the.NET Framework Data Provider for SQL Server(SqlConnection).COM applications,all other then.Net applicatio
43、ns Use the SQL Native Client if you are accessing an SQL Server 2005 and need the new features of SQL Server 2005 such as MARS,encryption,xml data type etc.Continue use your current provider(OLE DB/ODBC through the MDAC package)if you are not connecting to an SQL Server 2005(thats quite obvious eh.)
44、or if you are connecting to an SQL Server 2005 but are not using any of the new SQL Server 2005 features.For more details on the differences between MDAC and SQL Native Client,read this msdn article Access ODBC Standard Security:Driver=Microsoft Access Driver(*.mdb);Dbq=C:mydatabase.mdb;Uid=Admin;Pw
45、d=;Workgroup:Driver=Microsoft Access Driver(*.mdb);Dbq=C:mydatabase.mdb;SystemDB=C:mydatabase.mdw;Exclusive:Driver=Microsoft Access Driver(*.mdb);Dbq=C:mydatabase.mdb;Exclusive=1;Uid=admin;Pwd=OLE DB,OleDbConnection(.NET)Standard security:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=somepathmydb.mdb
46、;User Id=admin;Password=;Workgroup(system database):Provider=Microsoft.Jet.OLEDB.4.0;Data Source=somepathmydb.mdb;Jet OLEDB:System Database=system.mdw;With password:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=somepathmydb.mdb;Jet OLEDB:Database Password=MyDbPassword;Oracle ODBC New version:Driver=M
47、icrosoft ODBC for Oracle;Server=OracleServer.world;Uid=Username;Pwd=asdasd;Old version:Driver=Microsoft ODBC Driver for Oracle;ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;OLE DB,OleDbConnection(.NET)Standard security:Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Passwor
48、d=asdasd;This ones from Microsoft,the following are from Oracle Standard Security:Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;Trusted Connection:Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;OracleConnection(.NET)Standard:Data Source=MyOracleDB;Inte
49、grated Security=yes;This one works only with Oracle 8i release 3or later Specifying username and password:Data Source=MyOracleDB;User Id=username;Password=passwd;Integrated Security=no;This one works only with Oracle 8i release 3or later Declare the OracleConnection:C#:using System.Data.OracleClient
50、;OracleConnection oOracleConn=new OracleConnection();oOracleConn.ConnectionString=my connection string;oOracleConn.Open();VB.NET:Imports System.Data.OracleClient Dim oOracleConn As OracleConnection=New OracleConnection()oOracleConn.ConnectionString=my connection stringoOracleConn.Open()Missing the S
51、ystem.Data.OracleClient namespace?Download.NET Managed Provider for Oracle Great article!Features of Oracle Data Provider for.NETby Rama Mohan G.at C#Corner Core Labs OraDirect(.NET)Standard:User ID=scott;Password=tiger;Host=ora;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0Rea
52、d more at Core Lab and the product page.Data Shape MS Data Shape:Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA;Data Source=orac;user id=username;password=mypwWant to learn data shaping?Check out 4GuyfFromRollas great article about Data Shaping MySQL MyODBC MyODBC 2.50 Loca
53、l database:Driver=mySQL;Server=localhost;Option=16834;Database=mydatabase;MyODBC 2.50 Remote database:Driver=mySQL;Server=;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;MyODBC 3.51 Local database:DRIVER=MySQL ODBC 3.51 Driver;SERVER=localhost;DATABASE=my
54、Database;USER=myUsername;PASSWORD=myPassword;OPTION=3;MyODBC 3.51 Remote database:DRIVER=MySQL ODBC 3.51 Driver;SERVER=;PORT=3306;DATABASE=myDatabase;USER=myUsername;PASSWORD=myPassword;OPTION=3;OLE DB,OleDbConnection(.NET)Standard:Provider=MySQLProv;Data Source=mydb;User Id=UserName;
55、Password=asdasd;Connector/Net 1.0(.NET)Standard:Server=Server;Database=Test;Uid=UserName;Pwd=asdasd;Download the driver at MySQL Developer Zone.Specifying port:Server=Server;Port=1234;Database=Test;Uid=UserName;Pwd=asdasd;Default port is 3306.Enter value-1 to use anamed pipe connection.Declare the M
56、ySqlClient connection:C#:using MySql.Data.MySqlClient;MySqlConnection oMySqlConn=new MySqlConnection();oMySqlConn.ConnectionString=Server=Server;Database=Test;Uid=UserName;Pwd=asdasd;oMySqlConn.Open();VB.NET:Imports MySql.Data.MySqlClient Dim oMySqlConn As MySqlConnection=New MySqlConnection()oMySql
57、Conn.ConnectionString=Server=Server;Database=Test;Uid=UserName;Pwd=asdasd;oMySqlConn.Open()MySqlConnection(.NET)eInfoDesigns.dbProvider:Data Source=server;Database=mydb;User ID=username;Password=pwd;Command Logging=falseThis one is used with eInfoDesigns dbProvider,an add-on to.NET Declare the MySqlConnection:C#:using eInfoDesigns.dbProvider.MySqlClient;MySqlConnection oMySqlConn=new MyS
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 建筑楼体防护网安装工程技术考核试卷
- 2023-2024学年广东省名校联盟高一下学期期中质量检测语文试题(解析版)
- 探索光的奥秘
- 江苏名校2024-2025学年高考化学试题模拟题及解析(全国Ⅰ卷)含解析
- 天津机电职业技术学院《材料成型原理与工艺》2023-2024学年第二学期期末试卷
- 苏州大学应用技术学院《生物反应工程实验》2023-2024学年第二学期期末试卷
- 四川省成都市龙泉驿区达标名校2025届初三第6次月考数学试题含解析
- 辽宁工业大学《藏族文化概论》2023-2024学年第一学期期末试卷
- 四川铁道职业学院《跨文化交际(日)》2023-2024学年第一学期期末试卷
- 2025年小学数学期末考试试卷及答案
- 022旋翼干式塑料表壳水表
- 特殊旅客的航空服务文献综述
- 实验模式动物斑马鱼左正宏
- 小学后进生转化记录表4篇-后进生转化
- 钢箱梁运输与安装施工方案
- DDI辅导员工迈向成功-辅导领导力系列
- 兼职教师任职承诺书
- 上海市2020年中考化学试卷(word版含解析)
- 史上最全的数列通项公式的求法15种
- 配电室高低压运行记录表
- 链路聚合的配置
评论
0/150
提交评论