0

Hi i am trying to connect to MS-SQLSERVER-2008 from asp. when i am running the asp page. i am getting this error

Error:

An error occurred on the server when processing the URL. Please contact the system administrator. 

What is the cause for this error. and is anything wrong in my code causing this error?

code:

<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>

when i add below line, i am getting error.

Connection.open "Driver={SQL Server};Server=127.0.0.1;Database=products;UID=sa;PWD=sa","sa","sa"

How can i resolve this?

CJAY
  • 6,989
  • 18
  • 64
  • 106

2 Answers2

1

Are you using the express version of SQL Server? If you are you need to put "\SQLEXPRESS" after the server name - eg "Server=127.0.0.1\SQLEXPRESS;Database=..."

You're using an ODBC connection string, which should work, but with SqlServer 2008 you would be better off looking at Native Client 10 or even OLEDB - see the links below

http://www.connectionstrings.com/sql-server-native-client-10-0-oledb-provider/

http://www.connectionstrings.com/microsoft-ole-db-provider-for-sql-server-sqloledb/

John
  • 4,658
  • 2
  • 14
  • 23
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>