asp怎么和MSSQL数据库连接啊

2025-01-04 08:53:10
推荐回答(4个)
回答1:

asp连接mysql的核心代码如下:
Set Conn=Server.CreateObject("ADODB.Connection") //采用ADO方式连接
servername="XINZHI-SERVER" //连接server名
dbname="User_info" //连接数据库
StrConn="Driver={ mysql odbc 3.51 driver};Server=(localhost);DataBase=hr;Uid=root;Pwd=root" //配置驱动
Conn.open strConn //打开连接
if err then //如果连接出错的处理
err.Clear
Set Conn = Nothing
Response.Write "数据库正在调整中,请稍候再试。"
Response.End
end if

回答2:

Dim Conn,ConnStr,DataServer,DataBase,DataUser,DataPass
DataServer = "xxxxxx" //服务器IP
DataBase = "xxxxxx" //数据库名
DataUser = "xxxxxx" //用户名
DataPass = "xxxxxx" //密码
ConnStr="Provider=SQLOLEDB.1;User ID="&DataUser&";Password="&DataPass&";Initial Catalog="&DataBase&";Data Source="&DataServer&""
Set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString=ConnStr
conn.Open

回答3:

<%

set cnn=server.CreateObject("adodb.connection")
cnn.open "provider=sqloledb;data source=121.198.44.40;uid=1;pwd=1;database=cn21059_db"
%>
uid 是数据账号 sa pwd是密码 cn21059_db是数据库名称

回答4:

给你完整的asp连接SQL语句
<%
Const SqlDatabaseName = "数据库名称"
Const SqlPassword = "密码"
Const SqlUsername = "用户名"
Const SqlLocalName = "服务器id"

Sub ConnectionDatabase
Dim ConnStr
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "

数据连接出错
"
Response.End
End If
End Sub
%>