数据库连接集锦

原创 2004年05月19日 13:38:00
 SQL Server  ODBC  OLE DB, OleDbConnection (.NET)  SqlConnection (.NET)  Data Shape  Read more

  •  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.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;"



  •  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 serverName/instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
  •  Prompt for username and password:
    oConn.Provider = "sqloledb"
    oConn.Properties("Prompt") = adPromptAlways
    oConn.Open "Data Source=Aron1;Initial Catalog=pubs;"

  •  Connect via an IP address:
    "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))


  •  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"
       (booth 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;"
       (booth connection strings produces the same result)
    (use serverName/instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
  •  Connect via an IP address:
    "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))
  •  Declare the SqlConnection:
    C#:
    using System.Data.SqlClient;
    SqlConnection oSQLConn = new SqlConnection();
    oSQLConn.ConnectionString="my connectionstring";
    oSQLConn.Open();

    VB.NET:
    Imports System.Data.SqlClient
    Dim oSQLConn As SqlConnection = New SqlConnection()
    oSQLConn.ConnectionString="my connectionstring"
    oSQLConn.Open()



  •  MS Data Shape
    "Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User ID=sa;Password=asdasd;"



 How to define wich network protocol to use

  • Example:
    "Provider=sqloledb;Data Source=190.190.200.100,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 (Windows 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 connectionstring properties

  • 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.

    Name Default Description
    Application Name   The name of the application, or '.Net SqlClient Data Provider' if no application name is provided.
    AttachDBFilename
    -or-
    extended properties
    -or-
    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'.
    Connect Timeout
    -or-
    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.
    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.
    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.
    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.
    Enlist 'true' When true, the pooler automatically enlists the connection in the creation thread's current transaction context.
    Initial Catalog
    -or-
    Database
      The name of the database.
    Integrated Security
    -or-
    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'.
    Max Pool Size 100 The maximum number of connections allowed in the pool.
    Min Pool Size 0 The minimum number of connections allowed in the pool.
    Network Library
    -or-
    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).
    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.
    Packet Size 8192 Size in bytes 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 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.
    Pooling 'true' When 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 login account.
    Workstation ID the local computer name The name of the workstation connecting to SQL Server.


    Note
    Use ; to separate each property.
    If a name occurs more than once, the value from the last one in the connectionstring will be used.
    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.
  •  
 ODBC  OLE DB, OleDbConnection (.NET)

  •  Standard Security:
    "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;"

  •  Workgroup:
    "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;SystemDB=C:/mydatabase.mdw;","admin", ""

  •  Exclusive:
    "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Exclusive=1;Uid=admin;Pwd="



  •  Standard security:
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;User Id=admin;Password=;"

  •  Workgroup (system database):
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;Jet OLEDB:System Database=system.mdw;","admin", ""

  •  With password:
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;","admin", ""

 ODBC  OLE DB, OleDbConnection (.NET)  OracleConnection (.NET)  Data Shape

  •  New version:
    "Driver={Microsoft 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;"



  •  Standard security:
    "Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Password=asdasd;"
    This one's 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;"



  •  Standard:
    "Data Source=Oracle8i;Integrated Security=yes";
    This one works only with Oracle 8i release 3 or later
  •  Declare the OracleConnection:
    C#:
    using System.Data.OracleClient;
    OracleConnection oOracleConn = new OracleConnection();
    oOracleConn.ConnectionString = "my connectionstring";
    oOracleConn.Open();

    VB.NET:
    Imports System.Data.OracleClient
    Dim oOracleConn As OracleConnection = New OracleConnection()
    oOracleConn.ConnectionString = "my connectionstring"
    oOracleConn.Open()



  •  MS Data Shape:
    "Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA;Data Source=orac;user id=username;password=mypw"

 ODBC  OLE DB, OleDbConnection (.NET)  MySqlConnection (.NET)

  •  Local database:
    "Driver={mySQL};Server=mySrvName;Option=16834;Database=mydatabase;"

  •  Remote database:
    "Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;"



  •  Standard:
    "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"


  •  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
  •  Declare the MySqlConnection:
    C#:
    using eInfoDesigns.dbProvider.MySqlClient;
    MySqlConnection oMySqlConn = new MySqlConnection();
    oMySqlConn.ConnectionString = "my connectionstring";
    oMySqlConn.Open();

    VB.NET:
    Imports eInfoDesigns.dbProvider.MySqlClient
    Dim oMySqlConn As MySqlConnection = New MySqlConnection()
    oMySqlConn.ConnectionString = "my connectionstring"
    oMySqlConn.Open()

 ODBC, Easysoft  ODBC, Intersolv

  •  Local computer:
    "Driver={Easysoft IB6 ODBC};Server=localhost;Database=localhost:C:/mydatabase.gdb;Uid=username;Pwd=password"

  •  Remote Computer:
    "Driver={Easysoft IB6 ODBC};Server=ComputerName;Database=ComputerName:C:/mydatabase.gdb;Uid=username;Pwd=password"
    Read more about this driver: Easysoft ODBC-Interbase driver >>


  •  Local computer:
    "Driver={INTERSOLV InterBase ODBC Driver (*.gdb)};Server=localhost;Database=localhost:C:/mydatabase.gdb;Uid=username;Pwd=password"

  •  Remote Computer:
    "Driver={INTERSOLV InterBase ODBC Driver (*.gdb)};Server=ComputerName;Database=ComputerName:C:/mydatabase.gdb;Uid=username;Pwd=password"
    This driver are provided by DataDirect Technologies >> (formerly Intersolv)



Read more about connecting to Interbase in this Borland Developer Network article http://community.borland.com/article/0,1410,27152,00.html

 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"

 ODBC

  •  Standard:
    "Driver={SYBASE SYSTEM 11};Srvr=Aron1;Uid=username;Pwd=password;"

  •  Intersolv 3.10:
    "Driver={INTERSOLV 3.10 32-BIT Sybase};Srvr=Aron1;Uid=username;Pwd=password;"

 ODBC  OLE DB

  •  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"



  •  IBM Informix OLE DB Provider:
    "Provider=Ifxoledbc.2;password=myPw;User ID=myUser;Data Source=dbName@serverName;Persist Security Info=true"
 Access  Oracle  MySQL  Interbase  IBM DB2  Sybase  Informix

数据库连接方法集锦

Java连接各种数据库的实例1、Oracle8/8i/9i数据库(thin模式)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance...
  • vic78
  • vic78
  • 2005年01月10日 16:17
  • 535

c#数据库连接集锦

1.C#连接连接Access程序代码: ------------------------------------------------------------------------------- ...
  • RainyLin
  • RainyLin
  • 2007年08月01日 18:27
  • 1028

开源集锦(六)GitHub开源控件(二)

pockethub/PocketHub Github开源Android客户端 https://github.com/pockethub/PocketHub
  • wds1181977
  • wds1181977
  • 2016年07月11日 09:56
  • 1025

双目测距与三维重建的OpenCV实现问题集锦(一)双目定标与双目校正

双目测距的基本原理 如上图所示,双目测距主要是利用了目标点在左右两幅视图上成像的横向坐标直接存在的差异(即视差 )与目标点到成像平面的距离Z存在着反比例的关系:Z=fT/d。“@scyscyao...
  • lihuajie1003
  • lihuajie1003
  • 2014年11月29日 12:36
  • 1388

iOS的C/C++笔试题集锦

转载自:http://www.huangyibiao.com/archives/108 题目解答 1. 打印结果 1 2 3 4 5 6 7 8   main() { ...
  • liangliang2727
  • liangliang2727
  • 2016年10月25日 10:32
  • 246

【蓝牙】蓝牙技术问题集锦

1.低功耗蓝牙和经典蓝牙不同? 设计目标和市场领域不同。 经典蓝牙:经典蓝牙的设计目的在于统一各地的计算和通信设备。让手机和电脑连接,但是经典蓝牙最广泛的应用还是音频的传输,比如让手机的音频传输到...
  • u014647208
  • u014647208
  • 2017年01月24日 17:58
  • 267

面试题汇总-

一、HTML和CSS 1、你做的页面在哪些流览器测试过?这些浏览器的内核分别是什么? IE: trident内核 Firefox:gecko内核 Safari:webkit内核 Opera:...
  • gyq04551
  • gyq04551
  • 2017年02月16日 12:24
  • 1583

C/C++语言经典、实用、趣味程序设计编程百例精解(9)

81.角谷猜想日本一位中学生发现一个奇妙的“定理”,请角谷教授证明,而教授无能为力,于是产生角谷猜想。猜想的内容是:任给一个自然数,若为偶数除以2,若为奇数则乘3加1,得到一个新的自然数后按照上面的法...
  • favory
  • favory
  • 2007年07月12日 10:49
  • 3756

eclipse 插件集锦

XML Schema Infoset Model (XSD) 功能:XML Schema Infoset Model 是个参考库提供用于测试,创建或者修改 W3C XML Schema 的 API。主...
  • kamiiyu
  • kamiiyu
  • 2006年08月03日 02:26
  • 997

经典算法集锦

计数排序 KMP算法 Astar算法 正在整理中......
  • starcuan
  • starcuan
  • 2014年02月07日 12:44
  • 1174
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:数据库连接集锦
举报原因:
原因补充:

(最多只允许输入30个字)