Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get database connection to work with ASP

Status
Not open for further replies.

neronikita

Technical User
Feb 20, 2002
159
US
I am trying to connect my ASP page to a SQL Server database. The page will not display, so I am assuming that it isn't getting a connection. I set up the DSN in my Datasources and tested it using the test button and that works. I'm wondering if the problem is that my DSN is set up on the computer I am using and the ASP page is sored on a different server where the SQL database is. That is running Server 2008 and SQL Server Standard. I just get a generic message, nothing that tells me what the problem is. I've worked with ASP in the past, but never had to create my own connection. Other non-database ASP pages do run. Any ideas? My code is below that I'm using just to test the connection.

TIA,
Di


<%@LANGUAGE="JAvaSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<%
Option Explicit
Response.Expires = 0
Dim objConn, objRS, strQuery
Dim strConnection
Set objConn = Server. CreateObject("ADODB. Connection")
strConnection = "DSN=ESI; Database=ESI; "
strConnection = strConnection & "UID=; PWD=; "
objConn. Open strConnection
strQuery = "SELECT empid, lastname FROM Employee "
strQuery = strQuery & "ORDER BY empid"
Set objRS = objConn. Execute(strQuery)
%>
<HTML>
<BODY>
All Employee IDs with Last Name: <BR><BR>
<%
While Not objRS. EOF
Response. Write obj RS("empid") & " ("
Response. Write objRS("lastname") & ") <BR>"
obj RS.MoveNext
Wend

objRS. close
objConn. close
Set objRS = Nothing
Set objConn = Nothing
%>




</body>
</html>
 
here's my DSN connection string - works like a charm everytime - I think you're missing the "DRIVER":

Code:
<%
set myCONN = Server.CreateObject("ADODB.Connection")
myCONN.connectionString = "Driver={SQL Server};DSN=myDSN;UID=myUID;PWD=myPWD;"
myCONN.open "DSN=myDSN","myUID","myPWD" 

%>


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Thanks. Also, if you have the SQL Server set to windows authorization, do you still need to put your userid and pw in there? THat would mean changing it anytime you change your windows/network pw.

Thanks,

Di
 
^

I've never set it for Windows Authentication, I like to keep the web users separate from the active directory users. That being said, I can't answer your question.

My suggestion (if you are able) to create a new user in SQL that is called something like "webUser" and give that user specific rights on the db you are using (i.e. read/write). You can restrict it further down to allow only access to specific tables or stored procedures....



--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top