?
Solved

Classic ASP/SQL Server Error

Posted on 2013-01-17
7
Medium Priority
?
526 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

840 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