Solved

Classic ASP/SQL Server Error

Posted on 2013-01-17
7
503 Views
Last Modified: 2013-01-18
I am getting sporadic error messages like this and I can't figure out why.  Any help would be much appreciated.

[Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "dbname" requested by the login. The login failed.
0
Comment
Question by:Bob Schneider
  • 3
  • 3
7 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 375 total points
ID: 38790378
Can you post your database connection string and database access code please.
0
 

Author Comment

by:Bob Schneider
ID: 38792583
An example of what I am doing is found below but it happens on different pages at different times.  Could it be related to traffic level?  Should I do something different in my code to better handle traffic?

Response.Buffer = True            'Turn buffering on
Response.Expires = -1            'Page expires immediately
                                                
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=DSNName; UID=uid;PWD=pwd"

			Set rs = Server.CreateObject("ADODB.Recordset")
			sql = "SELECT ... FROM ... ORDER BY..."
			rs.Open sql, conn, 1, 2
			Do While Not rs.EOF
				'get gender for series
				If i = 0 Then sSeriesGender = rs(4).Value
				RsltsArr(0,i) = rs(10).Value & "-" & Replace(rs(0).Value, "''", "'") & " " & Replace(rs(1).Value, "''", "'")
				RsltsArr(1,i) = Replace(rs(2).Value, "''", "'")
				RsltsArr(2,i) = GetGrade(rs(3).Value)
				RsltsArr(3,i) = rs(4).Value
				RsltsArr(4,i) = rs(5).Value
				RsltsArr(5,i) = rs(6).Value
				RsltsArr(6,i) = rs(7).Value
				RsltsArr(7,i) = rs(8).Value
				If CInt(rs(9).Value) = 0 Then
					RsltsArr(8,i) = "---"
				Else
					RsltsArr(8,i) = rs(9).Value
				End If
				i = i + 1
				ReDim Preserve RsltsArr(8, i)
				rs.MoveNext
			Loop
			rs.Close
			Set rs = Nothing

Open in new window

0
 
LVL 6

Assisted Solution

by:worthyking1
worthyking1 earned 125 total points
ID: 38793198
That error means that the login failed ie. your username or password is incorrect. Double check your connection string carefully and compare against yoru DSn setup.

As an aside, why are you using a DSn rather than a straight SQl connection?  I personally prefer a DSNless connection (less intermediaries to check when troubleshooting). Here's the standard connection string I use in almost all my coding:

"Driver={SQL Server};Server=(local);Database=MyDB;uid=MyUser;pwd=MyPswd"

or for non-local SQL server

"Driver={SQL Server};Server=MySQLServer;Database=MyDB;uid=MyUser;pwd=MyPswd"
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 375 total points
ID: 38794422
As worthyking1 says I would remove the DSN from the equation. I would also have a library function OpenDBConn(); which would contain the only code on the site which creates a DB connection. That way you can be 100% sure that every connection uses exactly the same details.

I would make sure you are only opening a single connection per page, using it to obtain all the data you need, then ensure you close it.

http://stackoverflow.com/questions/6505769/closing-sql-connections-in-regular-asp
0
 

Author Comment

by:Bob Schneider
ID: 38794432
Good information...some of which I am doing...some I am not...the problem is that it only happens occassionally.  And I do have a single connection open on any given page and I close it when the page is done rendering.  I will change from the dns and see if that helps at all.

Any other advice given that it is a sporadic issue?
0
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 375 total points
ID: 38794456
The first step is to make sure all your code is consistent... hence why I suggest putting the open connection code into a single site function so you are 100% sure you use the correct details every time.

And also minimise opening said connections - which it sounds like you are already doing.

If it still continues after that I would suspect your server, maybe its taking too long to connect, although one would expect a different error from that.
0
 

Author Comment

by:Bob Schneider
ID: 38794755
"If it still continues after that I would suspect your server, maybe its taking too long to connect, although one would expect a different error from that."

That is what I am suspecting but I wanted some validation.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now