UPDATE 3:
Since no one answered my first problem as suggested by @Timen i tried using the SQL SERVER Authentication.
I Enabled the SQL Authentication
through SQL SERVER MANAGEMENT STUDIO
and enabled sa
and set a simple password for it.(under .\sqlexpress).
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
This is the SQL Error log:
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>]
Old Question I am trying to connect to a database in two modes ( on my system the database is located under the SQLSERVER Data subfolder whereas in my customer system i want it to be next to my executable.For this i have two connection strings one for my own system which is :
"Data Source=.\SQLExpress;Initial Catalog=dbNegin;Integrated Security=True"
And one for the customer machine:
"Data Source=.\SQLExpress;AttachDbFilename=C:\Users\Master\Documents\Visual Studio 2010\Projects\ProjectNegin\ProjectNegin\bin\Debug\dbNegin.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
, The problem is i tried to test the second scenario on my system, I placed the latest Database next to my executable and changed the connection string and tried to run the application,For some sections of the application it connects to the database and retrieves information , but on some others it failes with this error:
Cannot open database "dbNegin" requested by the login. The login failed. Login failed for user 'Master-PC\Master'.
Master-PC\Master
is the name of my computer! I don't remember using it in my connection string and have no idea where it came from and how i can get rid of it.To be even worst, now my former connection string fails as well with this error !!.
I need to say this that before i try the my second connection string (the one next to executable file) i renamed the database inside SQLSERVER
DATA
sub folder so that i don't miss anything and i can only connect to the database through atatchfile method (to avoid the possible probable connection to the to my default database connection string)
When i tried to use my former connection string, i renamed back my database to its original name (i mean the one inside DATA sub folder ) . but i am still getting this error .
How can i solve this problem ?
UPDATE
:
When i tried using SQL SEVER MANAGEMENT STUDIO
to see my database the database reads as:
(Recovery Pending...)
and I cant do anything about it ( since it says it must be either repaired or dropped! and i cant find a repair menu !)
UPDATE 2:
I tried deleting the database form Management Studio and re attaching it ! After deleting it form the database lists in Management studio.
Now I can't re attach it again i get the error :
TITLE: Microsoft SQL Server Management Studio
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476
------------------------------ ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\New folder\dbNegin.mdf'. (Microsoft SQL Server, Error: 5123)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=10.00.2531&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476