SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Cannot open database “” requested by the login. The login failed. Login failed for user 'sa'


Cannot open database “” requested by the login. The login failed. Login failed for user 'sa'

Author
Message
Coderx7
Coderx7
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 32
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? Sad

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>]

AndrewSQLDBA
AndrewSQLDBA
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4344 Visits: 3427
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
Coderx7
Coderx7
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 32
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 ).
David Webb-CDS
David Webb-CDS
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3982 Visits: 8586
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
Coderx7
Coderx7
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 32
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?
AndrewSQLDBA
AndrewSQLDBA
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4344 Visits: 3427
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
Coderx7
Coderx7
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 32
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
AndrewSQLDBA
AndrewSQLDBA
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4344 Visits: 3427
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
Coderx7
Coderx7
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 32
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?
Coderx7
Coderx7
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 32
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 Smile
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 Smile
Thank you very much .
:-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search