各种数据库的连接串(总结DSN的使用方法)
第一种 - 这种方法用在ACCESS中最多
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("aspfree.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
第二种-这种方法用在SQL SERVER中多
strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name
set conn = server.createobject("adodb.connection")
conn.open strconn
第三种
strconn="Driver={MicrosoftAccessDriver(*.mdb)};DBQ=F:\Inetpub\wwwroot\somedir\db1.mdb;DefaultDir=f:\Inetpub\wwwroot\somedir;uid=LoginID;pwd=Password;DriverId=25;FIL=MSAccess;" set conn = server.createobject("adodb.connection")
conn.open strconn
第四种运用系统数据源
The following uses a Data Source Name:
set conn = server.createobject("adodb.connection")
conn.open "Example"
'This is created in the Control Panel using the 32 bit ODBC Driver. If you don't know how to setup here is a perfect example on ActiveServerPages.com (click here to find how to create System and File DSN's!
第五种运用ODBC数据源,前提是你必须在控制面板的ODBC中设置数据源
set rs = server.createobject("adodb.recordset")
rs.open "tblname", "DSNName", 3, 3
转载http://www.chinaitpower.com/A/2001-11-08/4246.html
---------------------------------------------------------------
各种数据库的连接串
将连接方式分为两大类,一类是OLEDB方式,一类是ODBC方式。收集了一段时间,整理出来,欢迎补充和修正。谢谢。
ADO.NET方式的连接与ADO类似,这里不加整理。
数据库连接串:
****A.OLEDB方式:
1.Oracle
标准连接(Standard Security):
"Provider=msdaora;Data Source=MyOracleDB;User Id=UserName;Password=asdasd;"
这是Microsoft的格式, 下面是Oracle的格式(提供者不同)
"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=Username;Password=asdasd;"
注意:"Data Source=" 必须根据相应的命名方法设置为Net8名称。例如对于局部命名,它是tnsnames.ora中的别名,对于Oracle命 名,它是Net8网络服务名。
信任连接(Trusted Connection):
"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;"
或者设置user ID为 "/"
"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=/;Password=;"
2.SQL Server
标准连接(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;"
(如果连接一个具体的已命名SQLServer实例,使用Data Source=Servere Name\Instance Name;但仅适用于 SQLServer2000)例 如:"Provider=sqloledb;Data Source=MyServerName\MyInstanceName;Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;"
连接时弹出输入用户名和口令对话框:
Conn.Provider = "sqloledb"
Conn.Properties("Prompt") = adPromptAlways
Conn.Open "Data Source=Aron1;Initial Catalog=pubs;"
通过IP地址连接:
"Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;UserID=sa;Password=asdasd;"
(DBMSSOCN=TCP/IP代替Named Pipes, Data Source的末尾是需要使用的端口号(缺省为1433))
3.Access
标准连接(Standard Security):
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"
组连接 (系统数据库)
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;","admin", ""
带口令的连接:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;","admin", ""
4.MySQL
标准连接:
"Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;"
Data Source是MySQL数据库的名字,也可以使用server=localhost;DB=test
5.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"
AS400
"Provider=IBMDA400;Data source=myAS400;User Id=myUsername;Password=myPassword;"
6.Excel
标准连接(Standa