ASP中的數據庫聯接Function
<%
'聯接txt,csv檔案
Function Opendb_csv(csv_file_path)
Application.Lock
Dim csvconn
Set csvconn = Server.CreateObject("ADODB.Connection")
csvconn.ConnectionTimeout = 25
csvconn.CommandTimeout = 60
csvconn.open "Provider=MSDASQL.1;Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ="+csv_file_path
Set Opendb_csv = csvconn
Application.UnLock
End Function
'查詢是用下面的語句
set csvrs=conn_csv.execute("select * from ["+table+".csv]")
'sqlserver聯接
function SQLConn()
Application.Lock
'建立SQL Connection
const strDB = "ASOVF" '數據庫名
const strIP = "br002" '聯接的IP地址,本地用localhost
const strID = "sa" '用戶名
const strPW = "000000" '密碼
dim connsql
Set connsql=Server.CreateObject("ADODB.Connection")
'connsql.ConnectionTimeout = 25 'sql鏈接時間
'connsql.CommandTimeout = 60 '命令執行時間
connsql.open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID="+strID+";Password="+strPW+";Initial Catalog="+strDB+";Data Source="+strIP
set SQLConn=connsql
Application.unLock
end function
'visual foxpro聯接
function VFConn()
Application.Lock
'連接VF數據庫
dim connvf
set connvf = Server.CreateObject("ADODB.Connection")
connvf.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=E:\A20050915_ord\usr\aso\data;Exclusive=No;"
set VFConn=connvf
Application.unLock
end function
'access聯接
Function Opendb()
Application.Lock
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionTimeout = 25
conn.CommandTimeout = 60
conn.open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID="+strID+";Password="+strPW+";Initial Catalog="+strDB+";Data Source="+strIP
'conn.open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(mdb_path)
Set Opendb = conn
Application.UnLock
End Function
%>
'聯接txt,csv檔案
Function Opendb_csv(csv_file_path)
Application.Lock
Dim csvconn
Set csvconn = Server.CreateObject("ADODB.Connection")
csvconn.ConnectionTimeout = 25
csvconn.CommandTimeout = 60
csvconn.open "Provider=MSDASQL.1;Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ="+csv_file_path
Set Opendb_csv = csvconn
Application.UnLock
End Function
'查詢是用下面的語句
set csvrs=conn_csv.execute("select * from ["+table+".csv]")
'sqlserver聯接
function SQLConn()
Application.Lock
'建立SQL Connection
const strDB = "ASOVF" '數據庫名
const strIP = "br002" '聯接的IP地址,本地用localhost
const strID = "sa" '用戶名
const strPW = "000000" '密碼
dim connsql
Set connsql=Server.CreateObject("ADODB.Connection")
'connsql.ConnectionTimeout = 25 'sql鏈接時間
'connsql.CommandTimeout = 60 '命令執行時間
connsql.open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID="+strID+";Password="+strPW+";Initial Catalog="+strDB+";Data Source="+strIP
set SQLConn=connsql
Application.unLock
end function
'visual foxpro聯接
function VFConn()
Application.Lock
'連接VF數據庫
dim connvf
set connvf = Server.CreateObject("ADODB.Connection")
connvf.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=E:\A20050915_ord\usr\aso\data;Exclusive=No;"
set VFConn=connvf
Application.unLock
end function
'access聯接
Function Opendb()
Application.Lock
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionTimeout = 25
conn.CommandTimeout = 60
conn.open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID="+strID+";Password="+strPW+";Initial Catalog="+strDB+";Data Source="+strIP
'conn.open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(mdb_path)
Set Opendb = conn
Application.UnLock
End Function
%>
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。