连接字符串

连接字符串,大家可以参考以下网站,非常全面: 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;

转载于:https://www.cnblogs.com/apchyzui/archive/2009/08/21/1551090.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值