?
Solved

Classic ASP/SQL Server Error

Posted on 2013-01-17
7
Medium Priority
?
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 1500 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 500 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 1500 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 1500 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 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