连接字符串

连接字符串,大家可以参考以下网站,非常全面:http://www.connectionstrings.com/
在此,仅列出常用的连接字符串。
特别声明,以下内容均摘录自上述网站。

Connection strings for SQL Server 2000, 7.0,2005:

1.    Standard Security

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

2.    Trusted Connection

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

3.    Connect via an IP address

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.

 

Connection strings for Sybase Adaptive Server Enterprise:

1.    Standard

Data Source='myASEserver';Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

 

Connection strings for Excel 2007:

1.    Xlsx files

This one is for connecting to Excel 2007 files with the Xlsx file extension. That is the Office Open XML format with macros disabled.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:"myFolder"myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";

    "HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite.

 

Connection strings for Excel:

1.    Standard

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:"MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";

 

Connection strings for Textfile:

1.    Delimited columns

       Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:"txtFilesFolder";Extended Properties="text;HDR=Yes;FMT=Delimited";

The delimiter can be specified in the registry at the following location:
HKEY_LOCAL_MACHINE " SOFTWARE " Microsoft " Jet " 4.0 " Engines " Text
"Format" = "TabDelimited"
or
"Format" = "Delimited(;)"

 

2.    Fixed length columns

       Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:"txtFilesFolder";Extended Properties="text;HDR=Yes;FMT=Fixed";

"HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite.

To specify each columns length use the Schema.ini file. See description below.

Important note!
The quota " in the string needs to be escaped using your language specific escape syntax.
c#, c++   ""
VB6, VBScript   ""
xml (web.config etc)   "
or maybe use a single quota '.

 

Connection strings for Access 2007:

1.    Standard security

       Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:"myFolder"myAccess2007file.accdb;Persist Security Info=False;

2.    With database password

       This is the connection string to use when you have an Access 2007 database protected with a password using the "Set Database Password" function in Access.

       Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:"myFolder"myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;

 

Connection strings for Access:

1.    Standard security

       Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:"mydatabase.mdb;User Id=admin;Password=;

2.    With database password

       This is the connection string to use when you have an access database protected with a password using the Set Database Password function in Access.

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:"mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;

posted @ 2009-08-21 00:57  zui  阅读(375)  评论(0编辑  收藏  举报