Click to See Complete Forum and Search --> : Asp - Sql


IxxI
06-25-2003, 09:46 AM
I'm trying to connect to an SQL database using ASP before, and I've never used either of them before. I've looked at as many tutorials as possible but I still have a problem connecting to my database. The database is on a server (i.e. not my local machine but one which it has a connection to), and I've connected to it using ODBC (on my machine not through asp) and its set as a userDSN. But all the scripts I've found for checking a connection either don't work, or I'm implementing either the ASP or the SQL connection wrongly. Any help would be much appreciated.

IxxI

DaiWelsh
06-25-2003, 10:24 AM
From my vague recollection of ODBC you may want it to be a system DSN as a User DSN is specific to the user account and if the web sevrer is not running as the user the DSN is set up under it won't be found. This may explain why the direct test you do works?

Can I just clarify also, which machine the following are on:-
1) Database - on the server
2) DSN ?
3) ASP script?

Regards,

Dai

bloke
06-25-2003, 11:03 AM
I always use this:

<%
dim gstrConn

gstrConn = "DRIVER={SQL SERVER};SERVER=yourserver;DATABASE=yourdatabase;UID=sa;PWD=yourpassword"

set connection = server.createobject("adodb.connection")
connection.open gstrConn

set rsContract = server.createobject("adodb.recordset")
rsContract.Open "sp_your_sp" ,connection

%>

Any use to you?

IxxI
06-26-2003, 03:16 AM
Thanks everyone,
In answer to dai's question - Database - on the server, DSN - local machine, ASP script - local machine.
Also I've tried everything and I get errors - here's my script:


<%

Dim conn

strConn = "Provider=MSDASQL; DRIVER={SQL Server}; Database=Northwind; Server=ODIN; UID=sa; PWD=test;"

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open strConn

If conn.errors.count = 0 Then

Response.write "Connected OK"

Else

Response.write "Connection Failed"

End If

%>


And I get Connection Failed on my screen - anyone know why?? Thanks again,

IxxI

IxxI
06-26-2003, 07:29 AM
Tis OK - done it thanks...

IxxI