Click to See Complete Forum and Search --> : Database Connection Going Awray Within ASP Page


Avenue
09-13-2009, 10:29 PM
Hello Everyone,

I'm brand new to classic ASP and am practicing/experimenting with a simple HTML page which calls an ASP page after a user clicks a button. When the ASP page is called, a connection to my SQL Server 2005 database is created and values from a table which i've created are supposed to be returned to a web page. The problem i'm having is that i'm getting connection errors in IE whenever I click the button.

Now here's the thing - I did what I feel is an exhaustive web search and found nothing which helps me solve this problem. Also, the connection string which i'm using to connect to my SQL Server came directly from www.connectionstrings.com. The rest of this code was developed by looking at a combination of tutorial websites, specifically W3 Schools and another at www.haneng.com

My database name is ASP_Test and the table within the database is called Name. I'm simply trying to write the records from this table to display in the body of a web page.

Here's my very simple code within the ASP page which is being called from my HTML page - nothing complex is going on here:


<%@ Language = "VBScript" %>


<HTML>
<Body>
<%
'THIS PIECE OF CODE CAME FROM CONNECTIONSTRINGS.COM
cst = "Provider=SQLOLEDB;" & _
"Data Source=W2KSQL;" & _
"Initial Catalog=ASP_Test;" & _
"Integrated Security=SSPI"

set SQLConn = CreateObject("ADODB.Connection")
SQLConn.open cst

Query = "SELECT * FROM Name"

Set RS = SQLConn.Execute(Query)

'--------

'LOOP THROUGH THE RECORDS AND DISPLAY THEM
WHILE NOT RS.EOF
%>
<LI><%=RS("FName")%>: <%=RS("LName")%>
<%
RS.MoveNext
WEND

%>

</body>
</html>


The error which i'm returning in IE is here:


Error Type:
Microsoft OLE DB Provider for SQL Server (0x80004005)
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/ASP/FormData.asp, line 14


Line 14 in the above code, by the way, happens to be this specific line here in my Visual Studio editor:


SQLConn.open cst


Again, i'm a newbie with ASP and just trying to get the hang of it. I'm creating this page so that we know that we can connect ASP pages to our database at work as the Devs here are migrating their Excel VBA applications over to classic ASP.

Can anyone help me troubleshoot this connection error?

Thanks!!

Kuriyama
09-13-2009, 10:57 PM
Are you using a DSN connection or trying to connect directly to the DB? It looks like you are trying to use a DSN called W2KSQL. Are you sure that the username and password is set correctly for that? Is your DB on a different server than IIS?

Avenue
09-13-2009, 11:14 PM
Thanks for the reply -

I'm trying to connect directly to the database which is on a server called W2KSQL. My web pages, on the other hand, are on my local IIS server on my Windows XP machine.

Correct me if i'm wrong or simply misunderstand, but using the Provider name, Data Source and Initial Catalog means that i'm not using a DSN connection, correct?

Do I need to put my web pages in the web root folder on my server? Seems like it should work either way, but I could be wrong.

This should all be simpler than the variety of examples and craziness which i'm finding out there online. Once someone can help me i'm sure i'll be on my way from there.

Thanks!!

Kuriyama
09-14-2009, 01:09 AM
Try doing it by IP address. Also you will need to provide the username and password to the DB in your connection string.

yamaharuss
12-04-2009, 11:05 AM
Try:

"PROVIDER=SQLOLEDB;DATA SOURCE=myIPAddress;DATABASE=myDatabase;USER ID=myUserID;PASSWORD=myPassword;"