数据库连接字符串大全

 
  1.   
  2. [Link to]http://www.connectionstrings.com/ 
  3.  SQL Server 
  4.  ODBC 
  5.  Standard Security:
  6. "Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;" 
  7.  Trusted connection:
  8. "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;" 
  9.  Prompt for username and password:
  10. oConn.Properties("Prompt") = adPromptAlways
  11. oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;" 
  12.  OLE DB, OleDbConnection (.NET) 
  13.  Standard Security:
  14. "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
  15.  Trusted Connection:
  16. "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
  17. (use serverName/instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
  18.  Prompt for username and password:
  19. oConn.Provider = "sqloledb"
  20. oConn.Properties("Prompt") = adPromptAlways
  21. oConn.Open "Data Source=Aron1;Initial Catalog=pubs;" 
  22.  Connect via an IP address:
  23. "Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog= pubs;UserID=sa;Password=asdasd;" 
  24. (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
  25.  SqlConnection (.NET) 
  26.  Standard Security:
  27. "Data Source=Aron1;Initial Catalog= pubs;UserId=sa;Password=asdasd;" 
  28.    - or - 
  29. "Server=Aron1;Database=pubs;UserID=sa;Password=asdasd;Trusted_Connection=False" 
  30.    (booth connection strings produces the same result)
  31.  Trusted Connection:
  32. "Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
  33.    - or -< BR>"Server=Aron1;Database=pubs;Trusted_Connection=True;" 
  34.    (booth connection strings produces the same result)
  35. (use serverName/instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
  36.  Connect via an IP address:
  37. "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog= pubs;UserID=sa;Password=asdasd;" 
  38. (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
  39.  Declare the SqlConnection:
  40. C#:
  41. using System.Data.SqlClient;
  42. SqlConnection oSQLConn = new SqlConnection();
  43. oSQLConn.ConnectionString="my connectionstring";
  44. oSQLConn.Open();
  45. VB.NET:
  46. Imports System.Data.SqlClient
  47. Dim oSQLConn As SqlConnection = New SqlConnection()
  48. oSQLConn.ConnectionString="my connectionstring"
  49. oSQLConn.Open() 
  50.  Data Shape 
  51.  MS Data Shape
  52. "Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog= pubs;UserID=sa;Password=asdasd;" 
  53. Want to learn data shaping? Check out 4GuyfFromRolla's great article about Data Shaping >>
  54.  Read more 
  55.  How to define wich network protocol to use
  56. Example:
  57. "Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog= pubs;UserID=sa;Password=asdasd;" 
  58. Name  Network library  
  59. dbnmpntw  Win32 Named Pipes  
  60. dbmssocn  Win32 Winsock TCP/IP  
  61. dbmsspxn  Win32 SPX/IPX  
  62. dbmsvinn  Win32 Banyan Vines  
  63. dbmsrpcn  Win32 Multi-Protocol (Windows RPC) 
  64. Important note! 
  65. When connecting through the SQLOLEDB provider use the syntax Network Library=dbmssocn
  66. and when connecting through MSDASQL provider use the syntax Network=dbmssocn 
  67.  All SqlConnection connectionstring properties
  68. This table shows all connectionstring properties for the ADO.NET SqlConnection object. Most of the properties are also used in ADO. All properties and descriptions is from msdn. 
  69. Name  Default  Description  
  70. Application Name     The name of the application, or '.Net SqlClient Data Provider' if no application name is provided.  
  71. AttachDBFilename
  72. -or-
  73. extended properties
  74. -or-
  75. Initial File Name     The name of the primary file, including the full path name, of an attachable database. The database name must be specified with the keyword 'database'.  
  76. Connect Timeout
  77. -or-
  78. Connection Timeout  15  The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.  
  79. Connection Lifetime  0  When a connection is returned to the pool, its creation time is compared 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 balancing between a running server and a server just brought on-line.  
  80. Connection Reset  'true'  Determines whether the database connection is reset when being removed from the pool. Setting to 'false' avoids making an additional server round-trip when obtaining a connection, but the programmer must be aware that the connection state is not being reset.  
  81. Current Language     The SQL Server Language record name.  
  82. Data Source
  83. -or-
  84. Server
  85. -or-
  86. Address
  87. -or-
  88. Addr
  89. -or-
  90. Network Address     The name or network address of the instance of SQL Server to which to connect.  
  91. Enlist  'true'  When true, the pooler automatically enlists the connection in the creation thread's current transaction context.  
  92. Initial Catalog
  93. -or-
  94. Database     The name of the database.  
  95. Integrated Security
  96. -or-
  97. Trusted_Connection  'false'  Whether the connection is to be a secure connection or not. Recognized values are 'true''false', and 'sspi', which is equivalent to 'true'.  
  98. Max Pool Size  100  The maximum number of connections allowed in the pool.  
  99. Min Pool Size  0  The minimum number of connections allowed in the pool.  
  100. Network Library
  101. -or-
  102. Net  'dbmssocn'  The network library used to establish a connection to an instance of SQL Server. Supported values include dbnmpntw (Named Pipes), dbmsrpcn (Multiprotocol), dbmsadsn (Apple Talk), dbmsgnet (VIA), dbmsipcn (Shared Memory) and dbmsspxn (IPX/SPX), and dbmssocn (TCP/IP). 
  103. The corresponding network DLL must be installed on the system to which you connect. If you do not specify a network and you use a local server (for example, "." or "(local)"), shared memory is used.  
  104. Packet Size  8192  Size in bytes of the network packets used to communicate with an instance of SQL Server.  
  105. Password
  106. -or-
  107. Pwd     The password for the SQL Server account logging on.  
  108. Persist Security Info  'false'  When set to 'false', security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password.  
  109. Pooling  'true'  When true, the SQLConnection object is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool.  
  110. User ID     The SQL Server login account.  
  111. Workstation ID  the local computer name  The name of the workstation connecting to SQL Server. 
  112. Note 
  113. Use ; to separate each property.
  114. If a name occurs more than once, the value from the last one in the connectionstring will be used.
  115. If you are building your connectionstring in your app using values from user input fields, make sure the user can't change the connectionstring by inserting an additional property with another value within the user value. 
  116.  Access 
  117.  ODBC 
  118.  Standard Security:
  119. "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;" 
  120.  Workgroup:
  121. "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;SystemDB=C:/mydatabase.mdw;" 
  122.  Exclusive:
  123. "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Exclusive=1;Uid=admin;Pwd=" 
  124.  OLE DB, OleDbConnection (.NET) 
  125.  Standard security:
  126. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;User Id=admin;Password=;" 
  127.  Workgroup (system database):
  128. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;Jet OLEDB:System Database=system.mdw;" 
  129.  With password:
  130. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;" 
  131.  Oracle 
  132.  ODBC 
  133.  New version:
  134. "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;" 
  135.  Old version:
  136. "Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;" 
  137.  OLE DB, OleDbConnection (.NET) 
  138.  Standard security:
  139. "Provider=msdaora;Data Source= MyOracleDB;UserId=UserName;Password=asdasd;" 
  140. This one's from Microsoft, the following are from Oracle
  141.  Standard Security:
  142. "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;" 
  143.  Trusted Connection:
  144. "Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;" 
  145.  OracleConnection (.NET) 
  146.  Standard:
  147. "Data Source=Oracle8i;Integrated Security=yes"
  148. This one works only with Oracle 8i release 3 or later
  149.  Declare the OracleConnection:
  150. C#:
  151. using System.Data.OracleClient;
  152. OracleConnection oOracleConn = new OracleConnection();
  153. oOracleConn.ConnectionString = "my connectionstring";
  154. oOracleConn.Open();
  155. VB.NET:
  156. Imports System.Data.OracleClient
  157. Dim oOracleConn As OracleConnection = New OracleConnection()
  158. oOracleConn.ConnectionString = "my connectionstring"
  159. oOracleConn.Open() 
  160.  Core Labs OraDirect (.NET) 
  161.  Standard:
  162. "User ID=scott; Password=tiger; Host=ora; Pooling=true; Min Pool Size=0;Max Pool Size=100; Connection Lifetime=0" 
  163. Read more at Core Lab and the product page.
  164.  Data Shape 
  165.  MS Data Shape:
  166. "Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA;Data Source= orac;userid=username;password=mypw" 
  167. Want to learn data shaping? Check out 4GuyfFromRolla's great article about Data Shaping >>
  168.  MySQL 
  169.  ODBC 
  170.  Local database:
  171. "Driver={mySQL};Server=mySrvName;Option=16834;Database=mydatabase;" 
  172.  Remote database:
  173. "Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;" 
  174.  OLE DB, OleDbConnection (.NET) 
  175.  Standard:
  176. "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"
  177.  MySqlConnection (.NET) 
  178.  eInfoDesigns.dbProvider:
  179. "DataSource=server;Database= mydb;UserID=username;Password=pwd;Command Logging=false" 
  180. This one is used with eInfoDesigns dbProvider, an add-on to .NET
  181.  Declare the MySqlConnection:
  182. C#:
  183. using eInfoDesigns.dbProvider.MySqlClient;
  184. MySqlConnection oMySqlConn = new MySqlConnection();
  185. oMySqlConn.ConnectionString = "my connectionstring";
  186. oMySqlConn.Open();
  187. VB.NET:
  188. Imports eInfoDesigns.dbProvider.MySqlClient
  189. Dim oMySqlConn As MySqlConnection = New MySqlConnection()
  190. oMySqlConn.ConnectionString = "my connectionstring"
  191. oMySqlConn.Open() 
  192.  SevenObjects MySqlClient (.NET) 
  193.  Standard:
  194. "Host=server; UserName= myusername;Password=mypassword;Database=mydb;" 
  195. This is a freeware ADO.Net data provider from SevenObjects
  196.  Core Labs MySQLDirect (.NET) 
  197.  Standard:
  198. "User ID=root; Password=pwd; Host=localhost; Port= 3306;Database=test;Direct=true; Protocol=TCP; Compress=false; Pooling=true; Min Pool Size=0;Max Pool Size=100; Connection Lifetime=0" 
  199. Read more at Core Lab and the product page.
  200.  Interbase 
  201.  ODBC, Easysoft 
  202.  Local computer:
  203. "Driver={Easysoft IB6 ODBC};Server=localhost;Database=localhost:C:/mydatabase.gdb;Uid=username;Pwd=password" 
  204.  Remote Computer:
  205. < DIV> "Driver={EasysoftIB6ODBC};Server=ComputerName;Database=ComputerName:C:/mydatabase.gdb;Uid=username;Pwd=password" 
  206. Read more about this driver: Easysoft ODBC-Interbase driver >>
  207.  ODBC, Intersolv 
  208.  Local computer:
  209. "Driver={INTERSOLV InterBase ODBC Driver (*.gdb)};Server=localhost;Database=localhost:C:/mydatabase.gdb;Uid=username;Pwd=password" 
  210.  Remote Computer:
  211. "Driver= {INTERSOLV InterBaseODBCDriver(*.gdb)};Server=ComputerName;Database=ComputerName:C:/mydatabase.gdb;Uid=username;Pwd=password" 
  212. This driver are provided by DataDirect Technologies >> (formerly Intersolv) 
  213.  OLE DB, SIBPROvider 
  214.  Standard:
  215. "provider=sibprovider;location=localhost:;data source=c:/databases/gdbs/mygdb.gdb;user id=SYSDBA;password=masterkey" 
  216.  Specifying character set:
  217. "provider=sibprovider;location=localhost:;data source=c:/databases/gdbs/mygdb.gdb;user id=SYSDBA;password=masterkey;character set=ISO8859_1" 
  218.  Specifying role:
  219. "provider=sibprovider;location=localhost:;data source=c:/databases/gdbs/mygdb.gdb;userid=SYSDBA;password=masterkey;role=DIGITADORES" 
  220. Read more about SIBPROvider >> 
  221. Read more about connecting to Interbase in this Borland Developer Network article http://community.borland.com/article/0,1410,27152,00.html 
  222.  IBM DB2 
  223.  OLE DB, OleDbConnection (.NET) from ms 
  224.  TCP/IP:
  225. "Provider=DB2OLEDB;Network Transport Library=TCPIP;Network Address=XXX.XXX.XXX.XXX;Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW" 
  226.  APPC:
  227. "Provider=DB2OLEDB;APPC Local LU Alias=MyAlias;APPC Remote LU Alias=MyRemote;Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=MyUser;Password=MyPW" 
  228.  Sybase 
  229.  ODBC 
  230.  Standard Sybase System 12 (or 12.5) Enterprise Open Client:
  231. "Driver={SYBASE ASE ODBC Driver};Srvr=Aron1;Uid=username;Pwd=password" 
  232.  Standard Sybase System 11:
  233. "Driver= {SYBASESYSTEM11};Srvr=Aron1;Uid=username;Pwd=password;" 
  234. Do you know a userguide for Sybase System 11, 12, 12.5? E-mail the URL to connectionstrings.com now!! >> 
  235.  Intersolv 3.10:
  236. "Driver={INTERSOLV 3.10 32-BIT Sybase};Srvr=Aron1;Uid=username;Pwd=password;" 
  237.  Sybase SQL Anywhere (former Watcom SQL ODBC driver):
  238. "ODBC; Driver= SybaseSQLAnywhere5.0;DefaultDir=c:/dbfolder/;Dbf=c:/mydatabase.db;Uid=username;Pwd=password;Dsn=""""" 
  239. Note! The two double quota following the DSN parameter at the end are escaped quotas (VB syntax), you may have to change this to your language specific escape syntax. The empty DSN parameter is indeed critical as not including it will result in error 7778.
  240. Read more in the Sybase SQL Anywhere User Guide >> 
  241.  OLE DB 
  242.  Adaptive Server Anywhere (ASA):
  243. "Provider=ASAProv;Data source=myASA" 
  244. Read more in the ASA User Guide >> 
  245.  Adaptive Server Enterprise (ASE) with Data Source .IDS file:
  246. "Provider=Sybase ASE OLE DB Provider; Data source=myASE" 
  247. Note that you must create a Data Source .IDS file using the Sybase Data Administrator. These .IDS files resemble ODBC DSNs. 
  248.  Adaptive Server Enterprise (ASE):
  249. < DIV>"Provider=Sybase.ASEOLEDBProvider;Srvr=myASEserver,5000;Catalog= myDBname;UserId=username;Password=password" 
  250.    - some reports on problem using the above one, try the following as an alternative -
  251. "Provider=Sybase.ASEOLEDBProvider;Server Name=myASEserver,5000;Initial Catalog= myDBname;UserId=username;Password=password" 
  252. This one works only from Open Client 12.5 where the server port number feature works,燼llowing fully qualified connection strings to be used without defining燼ny .IDS Data Source files. 
  253.  Informix 
  254.  ODBC 
  255.  Informix 3.30:
  256. "Dsn='';Driver={INFORMIX 3.30 32 BIT};Host=hostname;Server=myserver;Service=service-name;Protocol=olsoctcp;Database=mydb;UID=username;PWD=myPwd 
  257.  Informix-CLI 2.5:
  258. "Driver={Informix-CLI 2.5 (32 Bit)};Server=myserver;Database=mydb;Uid=username;Pwd=myPwd" 
  259.  OLE DB 
  260.  IBM Informix OLE DB Provider:
  261. "Provider=Ifxoledbc.2;password=myPw;User ID=myUser;Data Source=dbName@serverName;Persist Security Info=true" 
  262.  Mimer SQL 
  263.  ODBC 
  264.  Standard Security:
  265. "Driver={MIMER};Database=mydb;Uid=myuser;Pwd=mypw;" 
  266.  Prompt for username and password:
  267. "Driver={MIMER};Database=mydb;" 
  268.  PostgreSQL 
  269.  Core Labs PostgreSQLDirect (.NET) 
  270.  Standard:
  271. "User ID=root; Password=pwd; Host=localhost; Port= 5432;Database=testdb;Pooling=true; Min Pool Size=0; Max Pool Size=100; Connection Lifetime=0" 
  272. Read more at Core Lab and the product page.
  273.  DSN 
  274.  ODBC 
  275.  DSN:
  276. "DSN=myDsn;Uid=username;Pwd=;" 
  277.  File DSN:
  278. "FILEDSN=c:/myData.dsn;Uid=username;Pwd=;" 
  279.  Excel 
  280.  ODBC 
  281.  Standard:
  282. "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:/MyExcel.xls;DefaultDir=c:/mypath;" 
  283.  OLE DB 
  284.  Standard:
  285. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" 
  286. "HDR=Yes;" indicates that the first row contains columnnames, not data
  287. "IMEX=1;" tells the driver to always read "intermixed" data columns as text
  288. TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
  289.  Text 
  290.  ODBC 
  291.  Standard:
  292. "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:/txtFilesFolder/;Extensions=asc,csv,tab,txt;" 
  293.  OLE DB 
  294.  Standard:
  295. < DIV> "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/txtFilesFolder/;ExtendedProperties=""text;HDR=Yes;FMT=Delimited""" 
  296. "HDR=Yes;" indicates that the first row contains columnnames, not data
  297.  DBF / FoxPro 
  298.  ODBC 
  299.  standard:
  300. "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:/mydbpath;" 
  301.  OLE DB, OleDbConnection (.NET) 
  302.  standard:
  303. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/folder;Extended Properties=dBASE IV;User ID=Admin;Password=" 
  304.  Visual FoxPro 
  305.  OLE DB, OleDbConnection (.NET) 
  306.  Database container (.DBC):
  307. "Provider=vfpoledb.1;Data Source=C:/MyDbFolder/MyDbContainer.dbc;Password=MyPassWord;Collating Sequence=machine" 
  308.  Free table directory:
  309. "Provider=vfpoledb.1;Data Source=C:/MyDataDirectory/;Password=MyPassWord;Collating Sequence=general" 
  310. Read more (Microsoft msdn) >>
  311.  ODBC 
  312.  Database container (.DBC):
  313. "Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=c:/myvfpdb.dbc;Exclusive=No;Collate=Machine;" 
  314.  Free Table directory:
  315. "Driver= {MicrosoftVisualFoxProDriver};SourceType=DBF;SourceDB=c:/myvfpdbfolder;Exclusive=No;Collate=Machine;" 
  316. "Collate=Machine" is the default setting, for other settings check the list of supported collating sequences >>
  317. Microsoft Visual Foxpro site: http://msdn.microsoft.com/vfoxpro 
  318.  Pervasive 
  319.  ODBC 
  320.  Standard:
  321. "Driver= {Pervasive ODBC ClientInterface};ServerName=srvname;dbq=@dbname" 
  322. Pervasive ODBC info >>
  323.  OLE DB 
  324.  Standard:
  325. "Provider=PervasiveOLEDB;Data Source=C:/path" 
  326. Pervasive OLE DB info >>
  327.  UDL 
  328.  UDL 
  329.  UDL:
  330. "File Name=c:/myDataLink.udl;" 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值