title: Cannot open database "" requested by the login. The login failed. Login failed for user 'sa'
body: <p><strong>UPDATE</strong> 3:<br>
  Since no one answered my first problem  as suggested by @Timen i tried using the SQL SERVER Authentication.<br>
  I Enabled the <code>SQL Authentication</code>through <code>SQL SERVER MANAGEMENT STUDIO</code> and enabled <code>sa</code> and set a simple password for it.(under .\sqlexpress). 
  I can Successfully log in to the database by <code>sa</code> and its password from <code>SQL SERVER MANAGEMENT STUDIO</code> but when i try to do so from my application it fails with this error message :</p>
  
  <blockquote>
    <p>Cannot open database "dbNegin" requested by the login. The login failed.
    Login failed for user 'sa'.</p>
  </blockquote>
  
  <p>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 :</p>
  
  <blockquote>
    <p>string sqlconstring = @"Data Source=.\sqlexpress;User ID=sa;Password=123456;Initial Catalog=dbNegin";</p>
  </blockquote>
  
  <p>My data base is attached by the way (its located in the address below )</p>
  
  <blockquote>
    <p>D:\TestDb\Debug\dbNegin.mdf</p>
  </blockquote>
  
  <p>This is the SQL Error log:</p>
  
  <pre><code>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: &lt;local machine&gt;]
  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: &lt;local machine&gt;]
  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: &lt;local machine&gt;]
  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: &lt;local machine&gt;]
  </code></pre>
  
  <hr>
  
  <p><strong>Old Question</strong>
  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 : </p>
  
  <blockquote>
    <p>"Data Source=.\SQLExpress;Initial Catalog=dbNegin;Integrated Security=True"</p>
  </blockquote>
  
  <p>And one for the customer machine:</p>
  
  <blockquote>
    <p>"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"</p>
  </blockquote>
  
  <p>, 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: </p>
  
  <blockquote>
    <p>Cannot open database "dbNegin" requested by the login. The login failed.
    Login failed for user 'Master-PC\Master'.</p>
  </blockquote>
  
  <p><code>Master-PC\Master</code> 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 !!.<br>
  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 <code>SQLSERVER</code> <code>DATA</code> 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 ?   </p>
  
  <hr>
  
  <p><code>UPDATE</code>:
  When i tried using <code>SQL SEVER MANAGEMENT STUDIO</code> to see my database the database reads as:</p>
  
  <blockquote>
    <p>(Recovery Pending...)  </p>
  </blockquote>
  
  <p>and I cant do anything about it ( since it says it must be either repaired or dropped! and i cant find a repair menu !)  </p>
  
  <p><code>UPDATE 2:</code>
  I tried deleting the database form Management Studio and re attaching it ! After deleting it form the database lists in Management studio.<br>
  Now I can't re attach it again i get the error  : </p>
  
  <blockquote>
    <h2>TITLE: Microsoft SQL Server Management Studio</h2>
    
    <p>Failed to retrieve data for this request.
    (Microsoft.SqlServer.Management.Sdk.Sfc)</p>
    
    <p>For help, click:
    <a href="http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&amp;LinkId=20476">http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&amp;LinkId=20476</a></p>
    
    <p>------------------------------ ADDITIONAL INFORMATION:</p>
    
    <p>An exception occurred while executing a Transact-SQL statement or
    batch. (Microsoft.SqlServer.ConnectionInfo)</p>
    
    <hr>
    
    <p>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)</p>
    
    <p>For help, click:
    <a href="http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&amp;ProdVer=10.00.2531&amp;EvtSrc=MSSQLServer&amp;EvtID=5123&amp;LinkId=20476">http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&amp;ProdVer=10.00.2531&amp;EvtSrc=MSSQLServer&amp;EvtID=5123&amp;LinkId=20476</a></p>
  </blockquote>