FretDancer69
September 22nd, 2011, 06:39 PM
I recently added an Existing mdf database file to my C# Windows Application project. A Connection was created succesfully and I can view the database tables in visual studio.
However, when I try to execute SQL commands in my code it seems its not recognizing the database. For example:
BUFETEConnectionString =" Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BUFETE.mdf;Integrated Security=True;User Instance=True"
That is the connection string Visual Studio created when I added the existing mdf. Now when I try this:
connectionStr = Properties.Settings.Default.BUFETEConnectionString;
connection = new SqlConnection();
connection.ConnectionString = connectionStr;
connection.Open();
System.Data.SqlClient.SqlCommand Command;
Command = new System.Data.SqlClient.SqlCommand("USE BUFETE");
Command.Connection = connection;
DataReader = Command.ExecuteReader();
I get a System.Data.SqlClient.SqlException, which message reads:
Database 'BUFETE' does not exist. Make sure that the name is entered correctly.
Why is this? I don't understand. I've been battling with this for hours and I just can't think of anything.
I tried executing the List Tables Store procedure and it is indeed not showing the database BUFETE.
What am I missing...? Please help.
However, when I try to execute SQL commands in my code it seems its not recognizing the database. For example:
BUFETEConnectionString =" Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BUFETE.mdf;Integrated Security=True;User Instance=True"
That is the connection string Visual Studio created when I added the existing mdf. Now when I try this:
connectionStr = Properties.Settings.Default.BUFETEConnectionString;
connection = new SqlConnection();
connection.ConnectionString = connectionStr;
connection.Open();
System.Data.SqlClient.SqlCommand Command;
Command = new System.Data.SqlClient.SqlCommand("USE BUFETE");
Command.Connection = connection;
DataReader = Command.ExecuteReader();
I get a System.Data.SqlClient.SqlException, which message reads:
Database 'BUFETE' does not exist. Make sure that the name is entered correctly.
Why is this? I don't understand. I've been battling with this for hours and I just can't think of anything.
I tried executing the List Tables Store procedure and it is indeed not showing the database BUFETE.
What am I missing...? Please help.