初学asp, 帮我看看这几行语句哪里错了, 多谢!
我的sql server 是 用戶:sa, 密码:空 登绿的
为什幺以下语句的结果是:not connected!
<%
On Error Resume Next
Dim ado
Dim rs
ado = Server.CreateObject( "adodb.connection ")
rs = Server.CreateObject( "adodb.RecordSet ")
ado.Open "PROVIDER=SQLOLEDB;UID=sa;DATABASE=Northwind "
If Err.Number <> 0 Then
response.write "not connected! "
Else
response.write "connected! "
End if
%>
------------------------------
而我在vb里面用下列语句确是: connected!的结果(当然vb我也不会用,只是试了一下)
Private Sub Command1_Click()
On Error Resume Next
Dim ado
Dim rs
ado = Server.CreateObject( "adodb.connection ")
rs = Server.CreateObject( "adodb.RecordSet ")
ado.Open "PROVIDER=SQLOLEDB;UID=sa;DATABASE=Northwind "
If Err.Number <> 0 Then
Label1.Caption = "connected! "
Else
Label1.Caption = "not connected! "
End If
End Sub
------解决方案--------------------Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlHostIP
SqlUsername = "sa " 'SQL数据库用户名
SqlPassword = "*** 'SQL数据库用户密码
SqlDatabaseName = "datebase " 'SQL数据库名
SqlHostIP = " " 'SQL主机IP地址(本地可用“127.0.0.1”或“(local)”,非本机请用真实IP)
dim ConnStr
dim conn
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlHostIP & "; "
Set conn = Server.CreateObject( "ADODB.Connection ")
conn.Open connstr
------解决方案--------------------会不会是ado的问题?ado = Server.CreateObject( "adodb.connection ")
可以换一种数据库连接方法试试。
------解决方案--------------------rs = Server.CreateObject( "adodb.RecordSet ")没用到