線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:5245
推到 Plurk!
推到 Facebook!

.NET中各種資料庫連接大全

 
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-06-12 01:49:13 IP:61.64.xxx.xxx 未訂閱
.NET中各種資料庫連接大全
http://www.postedu.cn/dtsy/asp/aspjc/77244731.htm      SQL Server 
·         ODBC     o         Standard Security:
"Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;" 
o         Trusted connection:
"Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;" 
o         Prompt for username and password:
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;" 
·         OLEDB, OleDbConnection (.NET)     o         Standard Security:
"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
o         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)
o         Prompt for username and password:
oConn.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Data Source=Aron1;Initial Catalog=pubs;" 
o         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))
·         SqlConnection (.NET)     o         Standard Security:
"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
o         Trusted Connection:
"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
(use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
o         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))
o         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() 
·         Data Shape     o         MS Data Shape
"Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=Aron1;Initial Catalog=pubs;User ID=sa;Password=asdasd;" 
·         Read more     ·         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. 
   Access 
·         ODBC     o         Standard Security:
"Driver={Microsoft Access Driver (*.mdb)};Dbq=\somepath\mydb.mdb;Uid=Admin;Pwd=asdasd;" 
o         Workgroup:
"Driver={Microsoft Access Driver (*.mdb)};Dbq=\somepath\mydb.mdb;SystemDB=\somepath\mydb.mdw;","admin", "" 
·         OLEDB, OleDbConnection (.NET)     o         Standard security:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=asdasd;" 
o         Workgroup (system database):
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;","admin", "" 
o         With password:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;","admin", "" 
   Oracle 
·         ODBC     o         New version:
"Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;" 
o         Old version:
"Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;" 
·         OLEDB, OleDbConnection (.NET)     o         Standard security:
"Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Password=asdasd;" 
This one's from Microsoft, the following are from Oracle
o         Standard Security:
"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;" 
o         Trusted Connection:
"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;" 
·         OracleConnection (.NET)     o         Standard:
"Data Source=Oracle8i;Integrated Security=yes"; 
This one works only with Oracle 8i release 3 or later
o         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() 
·         Data Shape     o         MS Data Shape:
"Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA;Data Source=orac;user id=username;password=mypw" 
   MySQL 
·         ODBC     o         Local database:
"Driver={mySQL};Server=mySrvName;Option=16834;Database=mydatabase;" 
o         Remote database:
"Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;" 
·         OLEDB, OleDbConnection (.NET)     o         Standard:
"Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;" 
·         MySqlConnection (.NET)     o         EID:
"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
o         Declare the MySqlConnection:
C#:
using EID.MySqlClient;
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "my connectionstring";
oMySqlConn.Open();     VB.NET:
Imports EID.MySqlClient
Dim oMySqlConn As MySqlConnection = New MySqlConnection()
oMySqlConn.ConnectionString = "my connectionstring"
oMySqlConn.Open() 
   IBM DB2 
·         OLEDB, OleDbConnection (.NET) from ms     o         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" 
o         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" 
   Sybase 
·         ODBC     o         Standard:
"Driver={SYBASE SYSTEM 11};Srvr=Aron1;Uid=username;Pwd=password;" 
o         Intersolv 3.10:
"Driver={INTERSOLV 3.10 32-BIT Sybase};Srvr=Aron1;Uid=username;Pwd=password;" 
   Informix 
·         ODBC     o         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 
o         Informix-CLI 2.5:
"Driver={Informix-CLI 2.5 (32 Bit)};Server=myserver;Database=mydb;Uid=username;Pwd=myPwd" 
   DSN 
·         ODBC     o         DSN:
"DSN=myDsn;Uid=username;Pwd=;" 
o         File DSN:
"FILEDSN=c:\myData.dsn;Uid=username;Pwd=;" 
   Excel 
·         ODBC     ·         Standard:
"Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\MyExcel.xls;DefaultDir=c:\mypath;" 
·         OLE DB     ·         Standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=Excel 8.0;HDR=Yes;" 
"HDR=Yes;" indicates that the first row contains columnnames, not data
   DBF / FoxPro 
·         ODBC     o         standard:
"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\mydbpath;" 
·         OLEDB, OleDbConnection (.NET)     o         standard:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder;Extended Properties=dBASE IV;User ID=Admin;Password=" 
   Pervasive 
·         ODBC     o         Standard:
"Driver={Pervasive ODBC Client Interface};ServerName=srvname;dbq=@dbname" 
   UDL 
·         UDL     o         UDL:
"File Name=c:\myDataLink.udl;"      
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-06-12 01:55:14 IP:61.64.xxx.xxx 未訂閱
通過ADO連接各種資料庫的字串翠集(中文)
http://www.topying.com/showfine.asp?id=36
在網路編程過程中,ADO(Activex Data Object)編程往往是不可少的工作,特別是開發電子商務網站。既然講到ADO資料物件,那?就順便簡單地介紹一下ADO資料物件及其功能。ADO資料物件共有七種獨立的物件,他們分別是連接物件(Connection)、記錄集物件(RecordSet)、域物件(Field)、命令物件(Command)、參數物件(Parameter)、屬性物件(Property)和錯誤物件(Error)。功能請參見附錄1。    ADO資料物件用來連接資料庫的方式有兩種,分別是ODBC和OLE DB方式,下面就分別介紹用這兩種方式連接資料庫的例子。    第一種:ODBC DSN-Less Connections    ODBC Driver for Access     ODBC Driver for dBASE     ODBC Driver for Excel     ODBC Driver for MySQL     ODBC Driver for Oracle     ODBC Driver for Paradox     ODBC Driver for SQL Server     ODBC Driver for Sybase     ODBC Driver for Sybase SQL Anywhere     ODBC Driver for Text     ODBC Driver for Teradata     ODBC Driver for Visual FoxPro    第二種:OLE DB Data Provider Connections    OLE DB Provider for Active Directory Service     OLE DB Provider for DB2     OLD DB Provider for Internet Publishing     OLE DB Provider for Index Server     OLE DB Provider for Microsoft Jet     OLE DB Provider for ODBC Databases     OLE DB Provider for Oracle (From Microsoft)     OLE DB Provider for Oracle (From Oracle)     OLE DB Provider for Simple Provider     OLE DB Provider for SQL Server    一、下面我就先講利用ODBC DSN來訪問資料庫,要完成這項工作,必須先通過“控制面板”—“管理工具”—“ODBC資料源”來建立一個資料源名,例如叫做TestData_Resoure。    1)   通過系統資料源(System DSN)的連接    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="DSN=TestData_Resoure;" & _               "Uid=AdminAccount;" & _               "Pwd=PassWord;    oConn.Open strConn    %>    2)   通過文件資料源(File DSN)的連接    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="FILEDSN=c:\somepath\mydb.dsn;" & _               "Uid=AdminAccount;" & _              "Pwd=PassWord;"    oConn.Open strConn    %>    3)   通過連接池(DSN-Less)的連接(ODBC Driver for AS/400)    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    strConn= "Driver={Client Access ODBC Driver (32-bit)};" & _              "System=myAS400;" & _              "Uid=myUsername;" & _              "Pwd=myPassword;"    oConn.Open strConn    %>    二、利用資料庫驅動程式直接訪問資料庫的連接字串。    1)  ODBC Driver for Access    ●      標準的也是比較常用的連接方法    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "Driver={Microsoft Access Driver (*.mdb)};" & _               "Dbq=”&Server.MapPath(“Testdb.mdb”); & _              "Uid=AdminAccount;" & _              "Pwd=Password;"    oConn.Open strConn    %>    ●      假如是一個工作組的系統資料庫,那?連接字串如下    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "Driver={Microsoft Access Driver (*.mdb)};" & _               "Dbq=c:\datapath\Testdb.mdb;" & _              "SystemDB=c:\datapath\Testdb.mdw;", _              "admin", ""    oConn.Open strConn    %>    ●      假如資料庫(MDB)是網路上共用的,那?連接字串如下    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={Microsoft Access Driver (*.mdb)};" & _              "Dbq=\\myServer\myShare\myPath\Testdb.mdb;"    oConn.Open strConn    %>    2) ODBC Driver for dBASE    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={Microsoft dBASE Driver (*.dbf)};" & _        "DriverID=277;" & _      "Dbq=c:\FilePath;"    oConn.Open strConn    %>    說明:這裏要注意的一點就是,在SQL查詢語句中要特別指定資料庫檔案名,例如:    oRs.Open "Select * From Testdb.dbf", oConn, , ,adCmdText    3) ODBC Driver for Excel    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={Microsoft Excel Driver (*.xls)};" & _              "DriverId=790;" & _              "Dbq=c:\filepath\myExecl.xls;"     oConn.Open strConn    %>    4) ODBC Driver for MySQL (通過 MyODBC驅動程式)    ●          連接到本地資料庫(local database)    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={mySQL};" & _       "Server=ServerName;" & _      "Option=16834;" & _           "Database=mydb;"    oConn.Open strConn    %>    ●          連接遠端資料庫(remote databas)    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={mySQL};Server=db1.database.com;Port=3306;" & _    "Option=131072;Stmt=;Database=mydb;Uid=myUsername;Pwd=myPassword;"    oConn.Open strConn    %>    5) ODBC Driver for Oracle    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={Microsoft ODBC for Oracle};" & _              "Server=OracleServer.world;" & _              "Uid=myUsername;" & _              "Pwd=myPassword;"    oConn.Open strConn    %>    6) ODBC Driver for Paradox    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={Microsoft Paradox Driver (*.db)};" & _              "DriverID=538;" & _              "Fil=Paradox 5.X;" & _              "DefaultDir=c:\dbpath\;" & _              "Dbq=c:\dbpath\;" & _              "CollatingSequence=ASCII;"    oConn.Open strConn    %>    7) ODBC Driver for SQL Server    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn="Driver={SQL Server};" & _                      "Server=MyServerName;" & _                  "Database=myDatabaseName;" & _                  "Uid=myUsername;" & _                  "Pwd=myPassword;"    oConn.Open strConn    %>    8) ODBC Driver for Sybase (通過Sybase System 11 ODBC Driver驅動程式)    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "Driver={SYBASE SYSTEM 11};" & _              "Srvr=myServerName;" & _               "Uid=myUsername;" & _               "Pwd=myPassword;"    oConn.Open strConn    %>    9) ODBC Driver for Sybase SQL Anywhere    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "ODBC; Driver=Sybase SQL Anywhere 5.0;" & _              "DefaultDir=c:\dbpath\;" & _              "Dbf=c:\sqlany50\mydb.db;" & _               "Uid=myUsername;" & _               "Pwd=myPassword;"              "Dsn="""";"    oConn.Open strConn    %>    10) ODBC Driver for Teradata    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "Provider=Teradata;" & _              "DBCName=MyDbcName;" & _               "Database=MyDatabaseName;" & _               "Uid=myUsername;" & _              "Pwd=myPassword;"    oConn.Open strConn    %>    11) ODBC Driver for Text    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _              "Dbq=c:\somepath\;" & _              "Extensions=asc,csv,tab,txt;" & _              "Persist Security Info=False"    oConn.Open strConn    %>    12) ODBC Driver for Visual FoxPro    ●使用資料庫容器(database container)連接方式    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn= "Driver={Microsoft Visual FoxPro Driver};" & _              "SourceType=DBC;" & _              "SourceDB=c:\somepath\mySourceDb.dbc;" & _              "Exclusive=No;"    oConn.Open strConn    %>    ●          不使用資料庫容器(database container)連接方式(即Free Table Directory方式)          <%        <%        Dim oConn,strConn        Set oConn=Server.CreateObject(“ADODB.Connection”)        StrConn= "Driver={Microsoft Visual FoxPro Driver};" & _              "SourceType=DBF;" & _              "SourceDB=c:\somepath\mySourceDbFolder;" & _              "Exclusive=No;"                                oConn.Open strConn                                 %>    二、接下來講使用OLE DB來連接資料庫的例子。    1)  OLE DB Provider for Active Directory Service    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=ADSDSOObject;" & _              "User Id=myUsername;" & _              "Password=myPassword;"    oConn.Open strConn    %>    2) OLE DB Provider for DB2    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=             "Provider=DB2OLEDB;" &                "Network Transport Library=TCPIP;" &                "Network Address=MyServer;" & _               "Package Collection=MyPackage;" &                "Host CCSID=1142"               "Initial Catalog=MyDB;" &                "User ID=MyUsername;" & _    "Password=MyPassword;"           oConn.Open strConn    %>    3) OLE DB Provider for Index Server    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=msidxs;" & _              "Data source=MyCatalog;"    oConn.Open strConn    %>    4) OLE DB Provider for Internet Publishing    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)     StrConn=  "Provider=MSDAIPP.DSO;" & _          "Data Source=http://mywebsite/myDir;" & _           "User Id=myUsername;" & _          "Password=myPassword;"    oConn.Open strConn    %>    5) OLE DB Provider for Microsoft Jet    ●  標準的也是常用的訪問方式。            <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=Microsoft.Jet.OLEDB.4.0;" & _              "Data Source=c:\somepath\myDb.mdb;" & _               "User Id=admin;" & _              "Password=;"    oConn.Open strConn    %>    ●      假如是一個工作組的系統資料庫,那?連接字串如下。    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=Microsoft.Jet.OLEDB.4.0;" & _              "Data Source=c:\somepath\mydb.mdb;" & _               "Jet OLEDB:System Database=MySystem.mdw;", _              "admin", ""    oConn.Open strConn    %>    注意:在使用4.0 OLE DB Provider 提供者的驅動程式時,要記得把MDB和MDW轉換成the 4.0 database格式。    ●      如果MDB是設置密碼的話,那?使用如下連接字串。    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _              "Data Source=c:\somepath\mydb.mdb;" & _               "Jet OLEDB:Database Password=MyDbPassword;", _              "admin", ""    ●      如果MDB是位於網路中並且是共用的話,那?使用如下連接字串。    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _          "Data Source=\\myServer\myShare\myPath\myDb.mdb;    ●      如果要想使用專有的方式來訪問資料庫,那?使用如下連接字串。    oConn.Mode = adModeShareExclusive    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _              "Data Source=c:\somepath\myDb.mdb;" & _              "User Id=admin;Password=;"    6)使用OLE DB Provider for Microsoft Jet來訪問Excel電子資料表。    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=Microsoft.Jet.OLEDB.4.0;" & _              "Data Source=c:\somepath\myExcelSpreadsheet.xls;" & _              "Extended Properties=""Excel 8.0;HDR=Yes;"";"    oConn.Open strConn    %>    說明:這裏的HDR=Yes的意思是,提供者訪問Excel電子資料表時沒有把第一排的資料加入到資料集中;而當HDR=No時的意思是提供者訪問Excel電子資料表時動作恰好跟上面所述相反。    7)OLE DB Provider for ODBC Databases    ●      訪問MS Access資料庫    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=MSDASQL;" & _               "Driver={Microsoft Access Driver (*.mdb)};" & _              "Dbq=c:\somepath\mydb.mdb;" & _              "Uid=myUsername;" & _              "Pwd=myPassword;"    oConn.Open strConn    %>    ●      訪問MS SQL Server 資料庫    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=MSDASQL;" & _               "Driver={SQL Server};" & _              "Server=myServerName;" & _              "Database=myDatabaseName;" & _              "Uid=myUsername;" & _              "Pwd=myPassword;"    oConn.Open strConn    %>    8) OLE DB Provider for Oracle (from Microsoft)    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=msdaora;" & _              "Data Source=MyOracleDB;" & _               "User Id=myUsername;" & _              "Password=myPassword;"    oConn.Open strConn    %>    9) OLE DB Provider for Oracle (from Oracle)    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=OraOLEDB.Oracle;" & _              "Data Source=MyOracleDB;" & _               "User Id=myUsername;" & _              "Password=myPassword;"    oConn.Open strConn    %>    10) OLE DB Provider for SQL Server    ●  標準連接方式    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=sqloledb;" & _               "Data Source=myServerName;" & _              "Initial Catalog=myDatabaseName;" & _              "User Id=myUsername;" & _              "Password=myPassword;"    oConn.Open strConn    %>    ●      通過機器的IP地址訪問    <%    Dim oConn,strConn    Set oConn=Server.CreateObject(“ADODB.Connection”)    StrConn=           "Provider=sqloledb;" & _              "Data Source=xxx.xxx.xxx.xxx,1433;" & _              "Network Library=DBMSSOCN;" & _              "Initial Catalog=myDatabaseName;" & _              "User ID=myUsername;" & _              "Password=myPassword;"    oConn.Open strConn    %>    說明:IP:xxx.xxx.xxx.xxx          SQLServer默認埠:1433
 
系統時間:2024-05-17 23:21:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!