Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Cannot open database “” requested by the login. The login failed. Login failed for user 'sa' Expand / Collapse
Author
Message
Posted Monday, February 25, 2013 1:06 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:38 PM
Points: 10, Visits: 31
Hello I am trying to use SQL Authentication to connect to a database . I am having extreme difficulties and my searches so far couldn't help me solve the problem.

I Enabled the SQL Authentication through SQL SERVER MANAGEMENT STUDIO and enabled sa and set a simple password for it.(under .\sqlexpress - i mean my server-name is ).
Now I can Successfully log in to the database by sa and its password from SQL SERVER MANAGEMENT STUDIO but when i try to do so from my application it fails with this error message :

Cannot open database "dbNegin" requested by the login. The login failed. Login failed for user 'sa'.



I need to say that i changed the database owner to sa as well, yet i get this error!!

How can i solve this now?

By the way this is the connection string used in my application to connect to the database :

string sqlconstring = @"Data Source=.\sqlexpress;User ID=sa;Password=123456;Initial Catalog=dbNegin";



My data base is attached by the way (its located in the address below )

" D:\TestDb\Debug\dbNegin.mdf"


And this is the latest error log:

quote:2013-02-25 21:51:18.59 spid51 Attempting to load library 'xpstar.dll' into memory. This is an informational message only. No user action is required.
2013-02-25 21:51:18.59 spid51 Using 'xpstar.dll' version '2007.100.1600' to execute extended stored procedure 'xp_instance_regread'. This is an informational message only; no user action is required.
2013-02-25 21:51:20.80 spid51 Starting up database 'C:\USERS\FRIEND\DESKTOP\RELEASE\DBNEGIN.MDF'.
2013-02-25 21:51:21.33 spid51 Starting up database 'mytestdb'.
2013-02-25 21:51:21.60 spid51 Starting up database 'C:\USERS\FRIEND\DESKTOP\RELEASE\DBNEGIN.MDF'.
2013-02-25 21:51:35.60 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 21:51:35.60 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2013-02-25 22:11:00.79 Server Server resumed execution after being idle 246 seconds: user activity awakened the server. This is an informational message only. No user action is required.
2013-02-25 22:11:00.97 spid51 Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2013-02-25 22:11:01.04 spid51 Using 'xplog70.dll' version '2007.100.1600' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.
2013-02-25 22:57:29.06 spid53 Starting up database 'C:\USERS\FRIEND\DESKTOP\RELEASE\DBNEGIN.MDF'.
2013-02-25 22:58:40.51 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 22:58:40.51 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2013-02-25 23:07:09.86 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 23:07:09.86 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2013-02-25 23:07:16.37 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 23:07:16.37 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
Post #1423758
Posted Monday, February 25, 2013 1:17 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 9:21 AM
Points: 977, Visits: 3,358
A couple things.
First
You should Never, Ever use the SysAdmin account for any app/website to database connections. That is for a SysAdmin only.

Second
What is your front-end app? That connection string does not look correct. What kind of app are you designing? Website? Windows app? .NET app?

Andrew SQLDBA
Post #1423763
Posted Monday, February 25, 2013 1:23 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:38 PM
Points: 10, Visits: 31
AndrewSQLDBA (2/25/2013)
A couple things.
First
You should Never, Ever use the SysAdmin account for any app/website to database connections. That is for a SysAdmin only.

Second
What is your front-end app? That connection string does not look correct. What kind of app are you designing? Website? Windows app? .NET app?

Andrew SQLDBA

hello thank you for your answer.
It is a Windows Form Application in C# . the application just runs pretty well on my system . but when i test it on my brothers laptop it fails ( I am trying to simulate situations i would face when deploying my application on the customer machine,thats why i am testing it on my brothers laptop ).
Post #1423765
Posted Monday, February 25, 2013 4:19 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 10:42 AM
Points: 863, Visits: 7,330
What database are you trying to open in the login? I've seen this when the database specified in an ODBC connection doesn't exist on the server or when the default database for the login doesn't exist.



And then again, I might be wrong ...
David Webb
Post #1423812
Posted Monday, February 25, 2013 7:23 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:38 PM
Points: 10, Visits: 31
David Webb-200187 (2/25/2013)
What database are you trying to open in the login? I've seen this when the database specified in an ODBC connection doesn't exist on the server or when the default database for the login doesn't exist.

i am trying to log in onto the dbNegin database,
i also provide the default database but there is something weird .first here is the pics :
As you can see when i attached the database , its name and address differs !!!



there is no such a file as :
C:\USERS\FRIEND\DESKTOP\RELEASE\RELEASE\DBNEGIN.MDF

The actual Address is :
C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA

I dont know why each time i attach the database it gets the first name !!(I used to attach the database from that address at first then i though mlets move the database to the sql Data sub folder, and test again maybe thats the cause ! thats why i renamed the former path to sth else and moved the database to the DATA subfolder in C:\. yet when ever i attach the database , the former path gets shown as database name !!!maybe thats the problem?causing issues?
Post #1423844
Posted Monday, February 25, 2013 7:30 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 9:21 AM
Points: 977, Visits: 3,358
I see now, that entire path statement is your database name. You do not name the database as a path statement to a file. SQL does not work that way. You simply name the database a single, descriptive name. Like "Recipe" or "ClubMembers" The database name is only a name that you will refer too. Now, if you place that entire path statement name as the name of your database, in your connection string, you will be able to connect successfully. But I would be that you will have a time trying to use a path statement in the connection string, without some sort of escape character.

Rename the database to a normal name.

Andrew SQLDBA
Post #1423845
Posted Monday, February 25, 2013 7:48 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:38 PM
Points: 10, Visits: 31
AndrewSQLDBA (2/25/2013)
I see now, that entire path statement is your database name. You do not name the database as a path statement to a file. SQL does not work that way. You simply name the database a single, descriptive name. Like "Recipe" or "ClubMembers" The database name is only a name that you will refer too. Now, if you place that entire path statement name as the name of your database, in your connection string, you will be able to connect successfully. But I would be that you will have a time trying to use a path statement in the connection string, without some sort of escape character.

Rename the database to a normal name.

Andrew SQLDBA

Thanks, but how should i do that, I didnt even change the name myself in first place!! after attaching it inside SSMS it showed up like that! and the filename is dbNegin.mdf as well , i have no idea where that name is come from!!
------------
And by the way i changed the connection string as you said, now parts of program connect to the database and some others generate an error , i captured a short video demonstrating the probelm here it is :
This is the code for the first section which works :
DataTable table = DBAPI.BatchRead("tblManbaa", "SELECT * FROM tblManbaa Where Status = 1");


And this is the code for the second part which fails:
gridview.DataSource = DBAPI.ExecuteSqlFunction("dbo.GetListOfFOroshbID", new string[] { API.CurrentSourceID, ID, "1" });


here is the video i took:
http://upload.ustmb.ir/do.php?filename=26_13capture-1.rar
or
http://upload.ustmb.ir/uploads/26_13capture-1.rar
Post #1423849
Posted Monday, February 25, 2013 8:05 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 9:21 AM
Points: 977, Visits: 3,358
You can try renaming the database database
EXEC sp_renamedb 'oldName', 'newName' 

Or you can detach it and attach it again, giving it a new name and a new location on the drive. I never place any database file in the same directory as all the SQL binaries. I create directories on separate drives, place the data file on one, and the log file on another.

EXEC sp_detach_db 'oldName', 'true' 

EXEC sp_attach_db 
@dbname = N'newName',
@filename1 = N'<Full Path to the Data File>.mdf',
@filename2 = N'<Full Path to the Log File>.ldf'

Andrew SQLDBA
Post #1423857
Posted Monday, February 25, 2013 8:21 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:38 PM
Points: 10, Visits: 31
AndrewSQLDBA (2/25/2013)
You can try renaming the database database
EXEC sp_renamedb 'oldName', 'newName' 

Or you can detach it and attach it again, giving it a new name and a new location on the drive. I never place any database file in the same directory as all the SQL binaries. I create directories on separate drives, place the data file on one, and the log file on another.

EXEC sp_detach_db 'oldName', 'true' 

EXEC sp_attach_db 
@dbname = N'newName',
@filename1 = N'<Full Path to the Data File>.mdf',
@filename2 = N'<Full Path to the Log File>.ldf'

Andrew SQLDBA

Thanks,i renamed it but the problem still exists .just like how its in the video clip i took and posted in my last post,would you have a look at it and see if it conveys anything?
Post #1423861
Posted Tuesday, February 26, 2013 12:25 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:38 PM
Points: 10, Visits: 31
master.huricane (2/25/2013)
AndrewSQLDBA (2/25/2013)
You can try renaming the database database
EXEC sp_renamedb 'oldName', 'newName' 

Or you can detach it and attach it again, giving it a new name and a new location on the drive. I never place any database file in the same directory as all the SQL binaries. I create directories on separate drives, place the data file on one, and the log file on another.

EXEC sp_detach_db 'oldName', 'true' 

EXEC sp_attach_db 
@dbname = N'newName',
@filename1 = N'<Full Path to the Data File>.mdf',
@filename2 = N'<Full Path to the Log File>.ldf'

Andrew SQLDBA

Thanks,i renamed it but the problem still exists .just like how its in the video clip i took and posted in my last post,would you have a look at it and see if it conveys anything?


Thank you very much :)
After renaming the database i needed to restart the SSMS and then specify the sa default database again (since after renaming it was lost and sa was pointing to nothing ) i specified the default database as dbNegin and all started working again :)
Thank you very much .
Post #1423901
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse