469,167 Members | 1,377 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

Connecting to SQL Server from ASP


I have MS SQL Server running on a server computer. I am trying
to connect to it via ASP from a .asp file created in a virtual
directory. I am using IIS as the web server. I am connecting
from a Windows 2000 computer.

When I go to Start -> Settings -> Control Panel
-> Administrative Tools -> ODBC Data Sources

I see a data source which uses SQL Server. I click on it,
click Configure..., then Next, and notice that if I place
the password I can connect fine from the "ODBC Data Source

However, when i try the following from ASP I get an error:


cncString = "DSN=X;" _
+ "Database=Y;" _
+ "UID=foo;" _
+ "PWD=bar"


cnc.Open cncString


The server error I get is the following:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified
/neil/Default.asp, line 30

This seems strange to me given that I can connect from the
ODBC Data Source Administrator without much trouble.

The only reason for this error which I can think of is that
the ODBC data sources may not be running on the web server
itself, but on yet a third machine, and I do not have access
to the web server itself right now, so that may be the problem.

Please let me know about any other probems which may arise
once I can get my hands on the web server itself,

Thank you so much for your suggestions and help,

Best Regards,

Neil Zanella

Jul 23 '05 #1
3 1297
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified
/neil/Default.asp, line 30

Make sure you created DSN with the name X


Jul 23 '05 #2
> <%

cncString = "DSN=X;" _
+ "Database=Y;" _
+ "UID=foo;" _
+ "PWD=bar"

Use & to concatenate strings in ASP, not +.

Jul 23 '05 #3
Okay, the two ways I have used to connect from plain old ASP are:

1) Save a System (not User) DSN, and then set the connection string
just as:

cncString = "DSN=SqlConnect"

(if SqlConnect is the name of the DSN)


2) Construct the whole connection within the ASP (dont touch ODBC at
all) such as:

cncString = "Provider=sqloledb;Data Source=" & myServer & ";Initial
Catalog=" & myDatabase & ";"

then add on either:

cncString = cncString & "Integrated Security=SSPI;"


cncString = cncString & "uid=" & myUser & ";pwd=" & myPassword & ";"

depending upon whether I'm using windows authentication or sql


May as well piggy back my own query on here, since it may turn out to
be relevant to OP:

We've recently been setting up an intranet site where we wanted to ID
the users from the browser using Windows Auth and then connect to the
DB as them using Windows Auth. Is there *still* no way of achieving
this when IIS/SQL are on different boxes? Any patches we may be
missing? We've switched to doing the browser authentication using basic
digest, but that isn't ideal. Windows/SQL are both 2000 with latest
stable SPs.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ann Marinas | last post: by
6 posts views Thread by Todd Brewer | last post: by
10 posts views Thread by mairhtin o'feannag | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.