Solved

Classic ASP/SQL Server Error

Posted on 2013-01-17
7
505 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

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