Solved

Classic ASP/SQL Server Error

Posted on 2013-01-17
7
502 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

19 Experts available now in Live!

Get 1:1 Help Now