建站代码网

热门标签

经典ASP连接字符串

sql 连接
************************

Dim connStr
connStr = "Provider=SQLOLEDB;Data Source=my-sql-server;UID=MyUsernmame;
           PWD=MyPassword; database=MyDatabase;"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionTimeOut = 30
objConn.ConnectionString = connStr
objConn.Open
SET objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open "SELECt * FROM my_table ORDER BY type asc",objConn,1,2

'执行Sql操作

     objRS.Close
SET objRS = Nothing


Access 2007/2010连接
************************

DIM objConn, objRS, dsn, dbPath
dsn = "Driver={Microsoft Access Driver (*.)};Dbq=C:MyWebsitedatabases
       MyDatabase2007.accdb;"

Set objConn = Server.CreateObject("ADODB.Connection")
    dbPath = Server.MapPath("MyDatabase2007.accdb")
    objConn.Open "Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath, "", ""
SET objRS = Server.CreateObject("ADODB.RecordSet")
    objRS.Open "SELECt * FROM my_table ORDER BY id asc",objConn,1,2

'执行Sql操作

     objRS.Close
SET objRS = Nothing


Access 2003 连接
************************

DIM objConn, objRS, dsn, dbPath
dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:MyWebsitedatabases
       MyDatabase2003.mdb;"

Set objConn = Server.CreateObject("ADODB.Connection")
    dbPath = Server.MapPath("MyDatabase.mdb")
    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath, "", ""
SET objRS = Server.CreateObject("ADODB.RecordSet")
    objRS.Open "SELECt * FROM my_table ORDER BY id asc",objConn,1,2

'执行sql操作

     objRS.Close
SET objRS = Nothing


热门信息

X