全部博文(2065)
分类: 数据库开发技术
2009-12-16 15:07:18
连接SQLSERVER驱动方式整理专题
[By hkebao@126.com]
本专题会介绍如下几种连接驱动分别是:
第一种方式:
Private Sub Test()
Dim rs
Dim n
For n = 0 To 2
Set
rs = Server.CreateObject("ADODB.Recordset")
Set
conn = Server.CreateObject("ADODB.Connection")
conn.Open
"DRIVER={SQL
Server};SERVER=localhost;DATABASE=tyspeed;UID=sa;PWD=hkebao"
rs.Open
"insert into speed(client_ip,server_ip,speed,date) values('123','3',12,'
conn.close
Next
end sub
通过:conn.Open
"DRIVER={SQL Server};SERVER=localhost;DATABASE=tyspeed;UID=sa;PWD=hkebao"
第二种方式:ODBC DSN
Private Sub Test()
Dim rs
Dim n
For n = 0 To 2
Set
rs = Server.CreateObject("ADODB.Recordset")
Set
conn = Server.CreateObject("ADODB.Connection")
conn.Open
"DSN=radius;UID=sa;PWD=hkebao"
rs.Open
"insert into speed(client_ip,server_ip,speed,date) values('123','3',12,'
'rs.Close
'Set
rs = Nothing
conn.close
Next
end sub
通过配置服务器的ODBC数据源:
conn.Open
"DSN=radius;UID=sa;PWD=hkebao"
第三种方式:File DSN
Private Sub Test()
Dim rs
Dim n
For n = 0 To 2
Set
rs = Server.CreateObject("ADODB.Recordset")
Set
conn = Server.CreateObject("ADODB.Connection")
conn.open
"FileDSN=test.dsn;UID=sa;PWD=hkebao;"
rs.Open
"insert into speed(client_ip,server_ip,speed,date) values('123','3',12,'
'rs.Close
'Set
rs = Nothing
conn.close
Next
end sub
通过配置数据源里面的FILE DSN方式进行访问到数据库。
conn.open
"FileDSN=test.dsn;UID=sa;PWD=hkebao;"
第四种方式:通过配置OLEDB 的方法进行数据库访问
Private Sub Test()
Dim rs
Dim n
For n = 0 To 2
Set
rs = Server.CreateObject("ADODB.Recordset")
Set
conn = Server.CreateObject("ADODB.Connection")
conn.open
"Provider=SQLOLEDB;server=localhost;database=hnebony;uid=sa;pwd=hkebao"
rs.Open
"insert into speed(client_ip,server_ip,speed,date) values('123','3',12,'
'rs.Close
'Set
rs = Nothing
conn.close
Next
end sub
通过这样的方式:
conn.open
"Provider=SQLOLEDB;server=localhost;database=hnebony;uid=sa;pwd=hkebao"
一共总结了四种方法。如果要用ODBC的话就需要配置数据源。比如现在有一K台服务器就得配置一K台服务器。非常麻烦。所以我不建议使用ODBC的方式。
现在主流是用第四种方法!以后如果想用MSSQL就可以走这条配置了!