• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
激情 希望 斗志昂扬
Records of growth process 专注微软技术
博客园    首页    新随笔    联系   管理    订阅  订阅

连接字符串

 注意:

 

  1:      当Integrated Security=false时,将在连接中指定用户ID和密码。
        当Integrated Security=true时,将使用当前的Windows帐户凭据进行身份验证。    
        可识别的值为 true、false、yes、no以及与true等效的sspi.


\"Integrated Security=SSPI\"与\"Trusted_Connection=yes\"相同

 

 2:web.config中AppSettings和ConnectionStrings的区别

 

 

 

AppSettings是ASP.NET1.1时期用的,在.NET Framework 2.0中,新增了ConnectionStrings. 

1.<connectionStrings> 
<connectionStrings> 
<add name="ConnectionStringName" connectionString="Data Source=服务器名;Initial Catalog=数据库名;User ID=用户;Password=密码" 
providerName
="System.Data.SqlClient" /> 
</connectionStrings> 

或是 

<connectionStrings> 
<add name="ConnectionStringName" connectionString="sever=服务器名;database=数据库名;User ID=用户;Password=密码" 
providerName
="System.Data.SqlClient" /> 
</connectionStrings> 

在 
<connectionStrings> 里,在页面还可以这样引用<%$ ConnectionString:Name%>. 

2.<appSettings> 

<add key="connectionstringName" value="data source=服务器名或IP;initial catalog=数据库名;persist security info=False;user id=用户;password=密码;packet size=4096"> 
</add> 

1)AppSettings 是在2003中常用的,ConnectionStrins是2005中常用的. 
2)使用ConnectionString的好处: 
第一:可将连接字符串加密,使用MS的一个加密工具即可。 
第二:可直接邦定的数据源控件,而不必写代码读出来再赋值给控件。 
第三:可方便的更换数据库平台,如换为Oracle数据库,只需修改providerName。 
3)写在 <appSettings >中用System.Configuration.ConfigurationManager.AppSettings["name"]检索值。 
写在 
<ConnectionStrings>中用System.Configuration.ConfigurationManager.ConnectionStrings["name"]检索值。
SQL 常用连接字符串 
Standard Security:
使用 SQL Server 身份验证: 

"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
   
- or -
"Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False" 

Trusted Connection:
使用 Windows 身份验证(信任连接): 

"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
   
- or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;" 


Connect via an IP address:
"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;" 

Enabling MARS (multiple active result sets):
仅仅支持 ADO.NET2.
0

"Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true" 

    Note
! 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 a database file on connect to a local SQL Server Express instance:

"Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;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 the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).

Using 
"User Instance" on a local SQL Server Express instance:

"Data Source=.\SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|\mydb.mdf;user instance=true;" 


        The 
"User Instance" functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer. To enable the functionality: sp_configure 'user instances enabled','1' (0 to disable)

        Using SQL Server 
2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer)

如果要进行同步
/异步访问需要在字符串后面继续添加 Asynchronous Processing=true 默认关闭

如果要开启 MARS 则加上 MultipleActiveResultSets
=True 默认开启。

 

 

 sql连接字符串参数详解

  • Application Name(应用程序名称):应用程序的名称。如果没有被指定的话,它的值为.NET SqlClient Data Provider(数据提供程序).
  • AttachDBFilename/extended properties(扩展属性)/Initial File Name(初始文件名):可连接数据库的主要文件的名称,包括完整路径名称。数据库名称必须用关键字数据库指定。
  • Connect Timeout(连接超时)/Connection Timeout(连接超时):一个到服务器的连接在终止之前等待的时间长度(以秒计),缺省值为15。
  • Connection Lifetime(连接生存时间):当一个连接被返回到连接池时,它的创建时间会与当前时间进行对比。如果这个时间跨度超过了连接的有效期的话,连接就被取消。其缺省值为0。
  • Connection Reset(连接重置):表示一个连接在从连接池中被移除时是否被重置。一个伪的有效在获得一个连接的时候就无需再进行一个额外的服务器来回运作,其缺省值为真。
  • Current Language(当前语言):SQL Server语言记录的名称。
  • Data Source(数据源)/Server(服务器)/Address(地址)/Addr(地址)/Network Address(网络地址):SQL Server实例的名称或网络地址。
  • Encrypt(加密):当值为真时,如果服务器安装了授权证书,SQL Server就会对所有在客户和服务器之间传输的数据使用SSL加密。被接受的值有true(真)、false(伪)、yes(是)和no(否)。
  • Enlist(登记):表示连接池程序是否会自动登记创建线程的当前事务语境中的连接,其缺省值为真。
  • Database(数据库)/Initial Catalog(初始编目):数据库的名称。
  • Integrated Security(集成安全)/Trusted Connection(受信连接):表示Windows认证是否被用来连接数据库。它可以被设置成真、伪或者是和真对等的sspi,其缺省值为伪。
  • Max Pool Size(连接池的最大容量):连接池允许的连接数的最大值,其缺省值为100。
  • Min Pool Size(连接池的最小容量):连接池允许的连接数的最小值,其缺省值为0。
  • Network Library(网络库)/Net(网络):用来建立到一个SQL Server实例的连接的网络库。支持的值包括: dbnmpntw (Named Pipes)、dbmsrpcn (Multiprotocol/RPC)、dbmsvinn(Banyan Vines)、dbmsspxn (IPX/SPX)和dbmssocn (TCP/IP)。协议的动态链接库必须被安装到适当的连接,其缺省值为TCP/IP。
  • Packet Size(数据包大小):用来和数据库通信的网络数据包的大小。其缺省值为8192。
  • Password(密码)/Pwd:与帐户名相对应的密码。
  • Persist Security Info(保持安全信息):用来确定一旦连接建立了以后安全信息是否可用。如果值为真的话,说明像用户名和密码这样对安全性比较敏感的数据可用,而如果值为伪则不可用。重置连接字符串将重新配置包括密码在内的所有连接字符串的值。其缺省值为伪。
  • Pooling(池):确定是否使用连接池。如果值为真的话,连接就要从适当的连接池中获得,或者,如果需要的话,连接将被创建,然后被加入合适的连接池中。其缺省值为真。
  • User ID(用户ID):用来登陆数据库的帐户名。
  • Workstation ID(工作站ID):连接到SQL Server的工作站的名称。其缺省值为本地计算机的名称。

     

     

    连接字符串实例

     

    在web.config中以自定义字符串的形式写连接字符串,这样的好处是不用因为改变网站所在磁盘的位置而重新改写web.config

    自定义方法:

    <appSettings>
        
    <add key ="ConnStrProvider" value ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="/>
        
    <add key ="DBLocation" value ="~/App_Data/db1.mdb"/>
      
    </appSettings >

    读取方法: 

    System.Configuration.ConfigurationSettings.AppSettings[
    "ConnStrProvider"] + Server.MapPath(ConfigurationSettings.AppSettings["DBLocation"]);

    直接在web.config中定义连接字符串,这样方便直观,但是必须是写数据库所在的绝对路径,

    在web.config中的定义:

     
    <connectionStrings>
        
    <remove name="AccessConnectionString"/>
        
    <add name="AccessConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\shiyan\exercise2\App_Data\db1.mdb" providerName="System.Data.OleDb"/>       
      
    </connectionStrings>

    读取方法:

    System.Configuration.ConfigurationManager.ConnectionStrings[
    "AccessConnectionString"].ConnectionString;

     

  •  

  •  

  •  

  •  

  • ADO.NET连接字符串(备查)

    名称
    ADO.NET连接字符串
    说明 ADO.NET连接字符串:SQL Server,SQL Server 2005,ACCESS,Oracle,MySQL,Interbase,IBM DB2,Sybase,Informix,Ingres,Mimer SQL,Lightbase,PostgreSQL,Paradox,DNS,Firebird,Excel ,Text,DBF / FoxPro,AS/400 (iSeries),Exchange,Visual FoxPro,Pervasive,UDL。
      1 - SQL Server
    2 - SQL Server 2005
    3 - ACCESS, Oracle
    4 - MySQL, Interbase, IBM DB2
    5 - Sybase, Informix, Ingres, Mimer SQL, Lightbase, PostgreSQL, Paradox, DNS
    6 - Firebird, Excel , Text, DBF / FoxPro, AS/400 (iSeries), Exchange, Visual FoxPro, Pervasive, UDL
    1
    SQL Server
    ODBC
    标准安全

    " Driver={SQL Server}; Server=Aron1; Database=pubs; Uid=sa; Pwd=asdasd; "

    //******************

    当连接远程服务器时,需指定地址、端口号和网络库
          "Driver={SQL Server};Server=130.120.110.001;Address=130.120.110.001,1052;Network=dbmssocn;
          Database=pubs;Uid=sa;Pwd=asdasd;"
          注:Address参数必须为IP地址,而且必须包括端口号

    信任的连接 " Driver={SQL Server}; Server=Aron1; Database=pubs; Trusted_Connection=yes; "
    提示输入用户名和密码 oConn.Properties(" Prompt" ) = adPromptAlways
    oConn.Open " Driver={SQL Server}; Server=Aron1; DataBase=pubs; "
    OLE DB, OleDbConnection (.NET)
    标准安全 " Provider=sqloledb; Data Source=Aron1; Initial Catalog=pubs; User Id=sa; Password=asdasd; "
    信任的连接 " Provider=sqloledb; Data Source=Aron1; Initial Catalog=pubs; Integrated Security=SSPI; "
    (use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
    提示输入用户名和密码 oConn.Provider = " sqloledb"
    oConn.Properties(" Prompt" ) = adPromptAlways
    oConn.Open " Data Source=Aron1; Initial Catalog=pubs; "
    IP地址连接管道 " Provider=sqloledb; Data Source=190.190.200.100,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 use (1433 is the default))
    SqlConnection (.NET)
    标准安全 " 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)
    信任的连接 " 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 serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
    IP地址连接管道 " Data Source=190.190.200.100,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 use (1433 is the default))
    定义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=" my connection string"
    oSQLConn.Open()
    Data Shape
    MS Data Shape " Provider=MSDataShape; Data Provider=SQLOLEDB; Data Source=Aron1; Initial Catalog=pubs; User ID=sa; Password=asdasd; "
    2
    SQL Server 2005
    SQL Native Client ODBC Driver
    标准安全 " Driver={SQL Native Client}; Server=Aron1; Database=pubs; UID=sa; PWD=asdasd; "
    信任的连接 " Driver={SQL Native Client}; Server=Aron1; Database=pubs; Trusted_Connection=yes; "
    Equivalents
    Integrated Security=SSPI equals Trusted_Connection=yes
    提示输入用户名和密码 oConn.Properties(" Prompt" ) = adPromptAlways
    oConn.Open " Driver={SQL Native Client}; Server=Aron1; DataBase=pubs; "
    授权的MARS(多重活动结果集) " Driver={SQL Native Client}; Server=Aron1; Database=pubs; Trusted_Connection=yes; MARS_Connection=yes"
    Equivalents
    MultipleActiveResultSets=true equals MARS_Connection=yes
    加密数据网络传输 " Driver={SQL Native Client}; Server=Aron1; Database=pubs; Trusted_Connection=yes; Encrypt=yes"
    在本地SQL服务器实例附加数据库文件 " Driver={SQL Native Client}; Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
    - or -
    " Driver={SQL Native Client}; Server=.\SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
    (use |DataDirectory| when your database file resides in the data directory)
    SQL Native Client OLE DB Provider
    标准安全 " Provider=SQLNCLI; Server=Aron1; Database=pubs; UID=sa; PWD=asdasd; "
    信任的连接 " Provider=SQLNCLI; Server=Aron1; Database=pubs; Trusted_Connection=yes; "
    Equivalents
    Integrated Security=SSPI equals Trusted_Connection=yes
    提示输入用户名和密码 oConn.Properties(" Prompt" ) = adPromptAlways
    oConn.Open " Provider=SQLNCLI; Server=Aron1; DataBase=pubs; "
    授权的MARS(多重活动结果集) " Provider=SQLNCLI; Server=Aron1; Database=pubs; Trusted_Connection=yes; MarsConn=yes"
    Equivalents
    MarsConn=yes equals MultipleActiveResultSets=true equals MARS_Connection=yes
    加密数据网络传输 " Provider=SQLNCLI; Server=Aron1; Database=pubs; Trusted_Connection=yes; Encrypt=yes"
    在本地SQL服务器实例附加数据库文件 " Provider=SQLNCLI; Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_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)
    SqlConnection (.NET)
    标准安全 " 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)
    信任的连接 " Data Source=Aron1; Initial Catalog=pubs; Integrated Security=SSPI; "
    - or -
    " Server=Aron1; Database=pubs; Trusted_Connection=True; "
    (both connection strings produces the same result)
    IP地址连接管道 " Data Source=190.190.200.100,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 use (1433 is the default))
    授权的MARS(多重活动结果集) " Server=Aron1; Database=pubs; Trusted_Connection=True; MultipleActiveResultSets=true"
    Note! Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1
    在本地SQL服务器实例附加数据库文件 " Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Database=dbname; Trusted_Connection=Yes; "
    - or -
    " Server=.\SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; "
    Using " User Instance" on a local SQL Server Express instance " Data Source=.\SQLExpress; integrated security=true; attachdbfilename=|DataDirectory|\mydb.mdf; user instance=true; "
    The " User Instance" functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer. To enable the functionality: sp_configure 'user instances enabled','1' (0 to disable)
    Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute " SERVERNAME" with the name of the computer)
    Context Connection - connecting to " self" from within your CLR stored prodedure/function
    Context Connection - connecting to " self" from within your CLR stored prodedure/function
    C# using(SqlConnection connection = new SqlConnection("context connection=true"))
    {
    connection.Open();
    // Use the connection
    }
    Visual Basic Using connection as new SqlConnection("context connection=true")
    connection.Open()
    ' Use the connection
    End Using
    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 applications
    COM applications, all other then .Net applications
    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 (that's quite obvious eh..) or if you are connecting to an SQL Server 2005 but are not using any of the new SQL Server 2005 features.
    3
    ACCESS
    ODBC
    标准安全 "Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\mydatabase.mdb; Uid=Admin; Pwd=; "
    工作组 "Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\mydatabase.mdb; SystemDB=C:\mydatabase.mdw; "
    独占 "Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\mydatabase.mdb; Exclusive=1; Uid=admin; Pwd="
    OLE DB, OleDbConnection (.NET)
    标准安全 "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\somepath\mydb.mdb; User Id=admin; Password=; "
    工作组 (system database) "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\somepath\mydb.mdb; Jet OLEDB:System Database=system.mdw; "
    使用密码 "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\somepath\mydb.mdb; Jet OLEDB:Database Password=MyDbPassword; "
     
    Oracle
    ODBC
    新版本 "Driver={Microsoft ODBC for Oracle}; Server=OracleServer.world; Uid=Username; Pwd=asdasd; "
    旧版本 "Driver={Microsoft ODBC Driver for Oracle}; ConnectString=OracleServer.world; Uid=myUsername; Pwd=myPassword; "
    OLE DB, OleDbConnection (.NET)
    标准安全 "Provider=msdaora; Data Source=MyOracleDB; User Id=UserName; Password=asdasd; "
    This one's from Microsoft, the following are from Oracle
    标准安全 "Provider=OraOLEDB.Oracle; Data Source=MyOracleDB; User Id=Username; Password=asdasd; "
    信任的连接 "Provider=OraOLEDB.Oracle; Data Source=MyOracleDB; OSAuthent=1; "
    OracleConnection (.NET)
    标准 "Data Source=MyOracleDB; Integrated Security=yes; "
    This one works only with Oracle 8i release 3 or later
    指定用户名和密码 "Data Source=MyOracleDB; User Id=username; Password=passwd; Integrated Security=no; "
    This one works only with Oracle 8i release 3 or later
    定义OracleConnection对象 C#:
    using System.Data.OracleClient;
    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 string"
    oOracleConn.Open()
    Core Labs OraDirect (.NET)
    标准 "User ID=scott; Password=tiger; Host=ora; Pooling=true; Min Pool Size=0; Max Pool Size=100; Connection Lifetime=0"
    Data Shape
    微软数据模型 "Provider=MSDataShape.1; Persist Security Info=False; Data Provider=MSDAORA; Data Source=orac; user id=username; password=mypw"
    4
    MySQL
    MyODBC
    MyODBC 2.50 本地数据库 "Driver={mySQL}; Server=localhost; Option=16834; Database=mydatabase; "
    MyODBC 2.50 远程数据库: "Driver={mySQL}; Server=data.domain.com; Port=3306; Option=131072; Stmt=; Database=my-database; Uid=username; Pwd=password; "
    MyODBC 3.51 本地数据库 "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=myDatabase; USER=myUsername; PASSWORD=myPassword; OPTION=3; "
    MyODBC 3.51 远程数据库 "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=data.domain.com; PORT=3306; DATABASE=myDatabase; USER=myUsername; PASSWORD=myPassword; OPTION=3; "
    OLE DB, OleDbConnection (.NET)
    标准 "Provider=MySQLProv; Data Source=mydb; User Id=UserName; Password=asdasd; "
    Connector/Net 1.0 (.NET)
    标准 "Server=Server; Database=Test; Uid=UserName; Pwd=asdasd; "
    Download the driver at MySQL Developer Zone
    指定端口 "Server=Server; Port=1234; Database=Test; Uid=UserName; Pwd=asdasd; "
    Default port is 3306. Enter value -1 to use a named pipe connection.
    定义mysqlclient 连接对象 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()
    oMySqlConn.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=false"
    This one is used with eInfoDesigns dbProvider, an add-on to .NET
    定义MySqlConnection连接对象 C#:
    using eInfoDesigns.dbProvider.MySqlClient;
    MySqlConnection oMySqlConn = new MySqlConnection();
    oMySqlConn.ConnectionString = "my connection string";
    oMySqlConn.Open();
    VB.NET:
    Imports eInfoDesigns.dbProvider.MySqlClient
    Dim oMySqlConn As MySqlConnection = New MySqlConnection()
    oMySqlConn.ConnectionString = "my connection string"
    oMySqlConn.Open()
    SevenObjects MySqlClient (.NET)
    标准 "Host=server; UserName=myusername; Password=mypassword; Database=mydb; "
    This is a freeware ADO.Net data provider from SevenObjects
    Core Labs MySQLDirect (.NET)
    标准 "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"
     
    Interbase
    ODBC, Easysoft
    本地计算机 "Driver={Easysoft IB6 ODBC}; Server=localhost; Database=localhost:C:\mydatabase.gdb; Uid=username; Pwd=password"
    远程计算机 "Driver={Easysoft IB6 ODBC}; Server=ComputerName; Database=ComputerName:C:\mydatabase.gdb; Uid=username; Pwd=password"
    ODBC, Intersolv
    本地计算机 "Driver={INTERSOLV InterBase ODBC Driver (*.gdb)}; Server=localhost; Database=localhost:C:\mydatabase.gdb; Uid=username; Pwd=password"
    远程计算机 "Driver={INTERSOLV InterBase ODBC Driver (*.gdb)}; Server=ComputerName; Database=ComputerName:C:\mydatabase.gdb; Uid=username; Pwd=password"
    OLE DB, SIBPROvider
    标准 "provider=sibprovider; location=localhost:; data source=c:\databases\gdbs\mygdb.gdb; user id=SYSDBA; password=masterkey"
    指定字符集 "provider=sibprovider; location=localhost:; data source=c:\databases\gdbs\mygdb.gdb; user id=SYSDBA; password=masterkey; character set=ISO8859_1"
    指定规则 "provider=sibprovider; location=localhost:; data source=c:\databases\gdbs\mygdb.gdb; user id=SYSDBA; password=masterkey; role=DIGITADORES"
     
    IBM DB2
    OLE DB, OleDbConnection (.NET) from ms
    TCP/IP "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"
    APPC "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"
    IBM's OLE DB Provider (shipped with IBM DB2 UDB v7 or above)
    TCP/IP "Provider=IBMDADB2; Database=sample; HOSTNAME=db2host; PROTOCOL=TCPIP; PORT=50000; uid=myUserName; pwd=myPwd;"
    ODBC
    标准 "driver={IBM DB2 ODBC DRIVER}; Database=myDbName; hostname=myServerName; port=myPortNum; protocol=TCPIP; uid=myUserName; pwd=myPwd"
    5
    Sybase
    ODBC
    标准 Sybase System 12 (or 12.5) Enterprise Open Client "Driver={SYBASE ASE ODBC Driver}; Srvr=Aron1; Uid=username; Pwd=password"
    标准 Sybase System 11 "Driver={SYBASE SYSTEM 11}; Srvr=Aron1; Uid=username; Pwd=password; Database=mydb"
    Intersolv 3.10 "Driver={INTERSOLV 3.10 32-BIT Sybase}; Srvr=Aron1; Uid=username; Pwd=password;"
    Sybase SQL Anywhere (former Watcom SQL ODBC driver) "ODBC; Driver=Sybase SQL Anywhere 5.0; DefaultDir=c:\dbfolder\; Dbf=c:\mydatabase.db; Uid=username; Pwd=password; Dsn="""""
    OLE DB
    Adaptive Server Anywhere (ASA) "Provider=ASAProv; Data source=myASA"
    Adaptive Server Enterprise (ASE) with Data Source .IDS file "Provider=Sybase ASE OLE DB Provider; Data source=myASE"
    Adaptive Server Enterprise (ASE) "Provider=Sybase.ASEOLEDBProvider; Srvr=myASEserver,5000; Catalog=myDBname; User Id=username; Password=password"
    - some reports on problem using the above one, try the following as an alternative -

    "Provider=Sybase.ASEOLEDBProvider; Server Name=myASEserver,5000; Initial Catalog=myDBname; User Id=username; Password=password"
    This one works only from Open Client 12.5 where the server port number feature works,following fully qualified connection strings to be used without definingfony .IDS Data Source files.

    AseConnection (.NET)
    标准 "Data Source='myASEserver'; Port=5000; Database='myDBname'; UID='username'; PWD='password'; "
    定义AseConnection连接对象 C#:
    using Sybase.Data.AseClient;
    AseConnection oCon = new AseConnection();
    oCon.ConnectionString="my connection string";
    oCon.Open();
    VB.NET:
    Imports System.Data.AseClient
    Dim oCon As AseConnection = New AseConnection()
    oCon.ConnectionString="my connection string"
    oCon.Open()
     
    Informix
    ODBC
    Informix 3.30 "Dsn=''; Driver={INFORMIX 3.30 32 BIT}; Host=hostname; Server=myserver; Service=service-name; Protocol=olsoctcp; Database=mydb; UID=username; PWD=myPwd"
    Informix-CLI 2.5 "Driver={Informix-CLI 2.5 (32 Bit)}; Server=myserver; Database=mydb; Uid=username; Pwd=myPwd"
    OLE DB
    IBM Informix OLE DB Provider "Provider=Ifxoledbc.2; password=myPw; User ID=myUser; Data Source=dbName@serverName; Persist Security Info=true"
     
    Ingres
    ODBC
    DSN-less "Provider=MSDASQL.1; DRIVER=Ingres; SRVR=xxxxx; DB=xxxxx; Persist Security Info=False; uid=xxxx; pwd=xxxxx; SELECTLOOPS=N; Extended Properties="""SERVER=xxxxx; DATABASE=xxxxx; SERVERTYPE=INGRES""
     
    Mimer SQL
    ODBC
    标准安全 "Driver={MIMER}; Database=mydb; Uid=myuser; Pwd=mypw; "
    提示输入用户名和密码 "Driver={MIMER}; Database=mydb;"
     
    Lightbase
    标准
    标准 "user=USERLOGIN; password=PASSWORD; UDB=USERBASE; server=SERVERNAME"
     
    PostgreSQL
    Core Labs PostgreSQLDirect (.NET)
    标准 "User ID=root; Password=pwd; Host=localhost; Port=5432; Database=testdb; Pooling=true; Min Pool Size=0; Max Pool Size=100; Connection Lifetime=0"
    PostgreSQL driver
    标准 "DRIVER={PostgreSQL}; SERVER=ipaddress; port=5432; DATABASE=dbname; UID=username; PWD=password; "
    Npgsql by pgFoundry (.NET)
    SSL activated "Server=127.0.0.1; Port=5432; Userid=myuserid; password=mypw; Protocol=3; SSL=true; Pooling=true; MinPoolSize=3; MaxPoolSize=20; Encoding=UNICODE; Timeout=20; SslMode=Require"
    Without SSL "Server=127.0.0.1; Port=5432; Userid=myuserid; password=mypw; Protocol=3; SSL=false; Pooling=true; MinPoolSize=1; MaxPoolSize=20; Encoding=UNICODE; Timeout=15; SslMode=Disable"
     
    Paradox
    ODBC
    5.X "Driver={Microsoft Paradox Driver (*.db )}; DriverID=538; Fil=Paradox 5.X; DefaultDir=c:\pathToDb\; Dbq=c:\pathToDb\; CollatingSequence=ASCII"
    7.X "Provider=MSDASQL.1; Persist Security Info=False; Mode=Read; Extended Properties='DSN=Paradox; DBQ=C:\myDb; DefaultDir=C:\myDb; DriverId=538; FIL=Paradox 7.X; MaxBufferSize=2048; PageTimeout=600; '; Initial Catalog=C:\myDb"
    OleDbConnection (.NET)
    标准 "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\myDb; Extended Properties=Paradox 5.x;"
     
    DNS
    ODBC
    DSN "DSN=myDsn; Uid=username; Pwd=; "
    File DSN "FILEDSN=c:\myData.dsn; Uid=username; Pwd=;"
    6
    Firebird
    ODBC - IBPhoenix Open Source
    标准 "DRIVER=Firebird/InterBase(r) driver; UID=SYSDBA; PWD=masterkey; DBNAME=D:\FIREBIRD\examples\TEST.FDB"
    .NET - Firebird .Net Data Provider
    标准 "User=SYSDBA; Password=masterkey; Database=SampleDatabase.fdb; DataSource=localhost; Port=3050; Dialect=3; Charset=NONE; Role=; Connection lifetime=15; Pooling=true; MinPoolSize=0; MaxPoolSize=50; Packet Size=8192; ServerType=0"
     
    Excel
    ODBC
    标准 "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=C:\MyExcel.xls; DefaultDir=c:\mypath; "
    OLE DB
    标准 "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\MyExcel.xls; Extended Properties=""Excel 8.0; HDR=Yes; IMEX=1"""
    "HDR=Yes; " indicates that the first row contains columnnames, not data
    "IMEX=1; " tells the driver to always read "intermixed" data columns as text
    TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
     
    Text
    ODBC
    标准 "Driver={Microsoft Text Driver (*.txt; *.csv)}; Dbq=c:\txtFilesFolder\; Extensions=asc,csv,tab,txt; "
    OLE DB
    标准 "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\txtFilesFolder\; Extended Properties=""text; HDR=Yes; FMT=Delimited"""
    "HDR=Yes; " indicates that the first row contains columnnames, not data
     
    DBF / FoxPro
    ODBC
    标准 "Driver={Microsoft dBASE Driver (*.dbf)}; DriverID=277; Dbq=c:\mydbpath; "
    OLE DB, OleDbConnection (.NET)
    标准 "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\folder; Extended Properties=dBASE IV; User ID=Admin; Password="
     
    AS/400 (iSeries)
    OLE DB, OleDbConnection (.NET)
    IBM Client Access OLE DB provider "PROVIDER=IBMDA400; DATA SOURCE=MY_SYSTEM_NAME; USER ID=myUserName; PASSWORD=myPwd"
    IBM Client Access OLE DB provider "PROVIDER=IBMDA400; DATA SOURCE=MY_SYSTEM_NAME; USER ID=myUserName; PASSWORD=myPwd; DEFAULT COLLECTION=MY_LIBRARY; "
    ODBC
    IBM Client Access ODBC driver "Driver={Client Access ODBC Driver (32-bit)}; System=my_system_name; Uid=myUserName; Pwd=myPwd"
     
    Exchange
    OLE DB
    Exchange OLE DB provider "ExOLEDB.DataSource"
    Specify store in the connection open command like this: conn.open "http://servername/mypublicstore"
     
    Visual FoxPro
    OLE DB, OleDbConnection (.NET)
    Database container (.DBC) "Provider=vfpoledb.1; Data Source=C:\MyDbFolder\MyDbContainer.dbc; Collating Sequence=machine"
    Free table directory "Provider=vfpoledb.1; Data Source=C:\MyDataDirectory\; Collating Sequence=general"
    Force the provider to use an ODBC DSN "Provider=vfpoledb.1; DSN=MyDSN"
    ODBC
    Database container (.DBC) "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBC; SourceDB=c:\myvfpdb.dbc; Exclusive=No; NULL=NO; Collate=Machine; BACKGROUNDFETCH=NO; DELETED=NO"
    Free Table directory "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBF; SourceDB=c:\myvfpdbfolder; Exclusive=No; Collate=Machine; NULL=NO; DELETED=NO; BACKGROUNDFETCH=NO"
     
    Pervasive
    ODBC
    标准: "Driver={Pervasive ODBC Client Interface}; ServerName=srvname; dbq=@dbname"
    OLD DB
    标准: "Provider=PervasiveOLEDB; Data Source=C:\path"
     
    UDL
    UDL
    UDL "File Name=c:\myDataLink.udl;"

     

  • posted @ 2009-04-05 13:56  贤  阅读(1401)  评论(0)    收藏  举报
    刷新页面返回顶部
    博客园  ©  2004-2025
    浙公网安备 33010602011771号 浙ICP备2021040463号-3