i have the following C# code for database connection in VS2013, which when i run i get the following error message, how can i get around it.
private void Form1_Load(object sender, EventArgs e)
{
//using (SqlConnection conn = new SqlConnection())
//{
try
{
//con = new System.Data.SqlServerCe.SqlCeConnection();
conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\\vs2013projects\\WFDBApp\\WFDBApp\\Dbapp.mdf;Integrated Security=True";
conn.Open();
MessageBox.Show("Openned database well");
conn.Close();
}
catch
{
MessageBox.Show("failed to connect");
//conn.Close();
}
//}
}
error message:
'WFDBApp.vshost.exe' (CLR v4.0.30319: WFDBApp.vshost.exe): Loaded 'c:\vs2013projects\WFDBApp\WFDBApp\bin\Debug\WFDBApp.exe'. Symbols loaded. 'WFDBApp.vshost.exe' (CLR v4.0.30319: WFDBApp.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'WFDBApp.vshost.exe' (CLR v4.0.30319: WFDBApp.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'WFDBApp.vshost.exe' (CLR v4.0.30319: WFDBApp.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll The thread 0x1788 has exited with code 259 (0x103). The thread 0x1428 has exited with code 259 (0x103). The program '[7048] WFDBApp.vshost.exe' has exited with code 0 (0x0).
(localDB)\v11.0
. You should remove thecatch
clause as that is discarding the error message and stack frame. – Dour High Archtry {/* code here */} catch (Exception ex){Console.WriteLine(ex.ToString()); Console.ReadLine();throw;}
ex.Message
only gets you the message portion, not stack trace and any inner exceptions. – John Saunders