您好我正在尝试从asp连接到MS-SQLSERVER-2008。当我运行asp页面时。我收到此错误
错误:
An error occurred on the server when processing the URL. Please contact the system administrator.
此错误的原因是什么。 我的代码中有什么问题导致了这个错误吗?
代码:
<html>
<head>
</head>
<body>
<%
Dim Connection
Dim Recordset
Dim SQL
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.open "Driver={SQL Server};Server=127.0.0.1;Database=products;UID=sa;PWD=sa","sa","sa"
SQL = "SELECT * FROM dbo.products_images"
Recordset.Open SQL,Connection;
If Recordset.EOF Then
Response.Write("No records returned.")
Else
Do While NOT Recordset.Eof
Response.write Recordset("ID")
Response.write Recordset("product_id")
Response.write Recordset("im_name")
Response.write Recordset("im_type")
Response.write "<br>"
Recordset.MoveNext
Loop
End If
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
</body>
</html>
当我添加以下行时,我收到错误。
Connection.open "Driver={SQL Server};Server=127.0.0.1;Database=products;UID=sa;PWD=sa","sa","sa"
我该如何解决这个问题?
答案 0 :(得分:1)
您使用的是SQL Server的快速版本吗?如果您需要在服务器名称后添加“\ SQLEXPRESS” - 例如"Server=127.0.0.1\SQLEXPRESS;Database=..."
您正在使用ODBC连接字符串,这应该可以使用,但是使用SqlServer 2008,您最好不要查看Native Client 10甚至是OLEDB - 请参阅下面的链接
http://www.connectionstrings.com/sql-server-native-client-10-0-oledb-provider/
http://www.connectionstrings.com/microsoft-ole-db-provider-for-sql-server-sqloledb/
答案 1 :(得分:0)
<html>
<head>
</head>
<body>
<%
Dim Connection
Dim Recordset
Dim SQL
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.open "Driver={SQL Server};Server=127.0.0.1;Database=products;UID=sa;PWD=sa"
SQL = "SELECT * FROM dbo.products_images"
Recordset.Open SQL,Connection
If Recordset.EOF Then
If Recordset.EOF Then
Response.Write("No records returned.")
Else
Do While NOT Recordset.Eof
Response.write Recordset("Dept_Id")
Response.write Recordset("Dept_Name")
Response.write "<br>"
Recordset.MoveNext
Loop
End If
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
</body>
</html>