I am writing a report manager program. I created a database from project -> new item -> service-based database. When I attempt to insert I am not getting an error. When I attempt to view the data in the database with Server Explorer -> Reports -> Show Table Data I'm getting an empty table. Upon refresh, I get this error
database cannot be imported. It is either an unsupported SQL server version or an unsupported database compatibility.
My code
private void btnSubmit_Click(object sender, EventArgs e)
{
string span = cbSpan.Text;
string reportData = tbReportInput.Text;
DateTime timeStamp = DateTime.Now;
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\App_Data\\ReportsDB.mdf;Integrated Security=True");
if (tbReportInput.Text == string.Empty)
{
MessageBox.Show("Report must have text!!!!");
}
else
{
try
{
string sqlQuery = "INSERT INTO dbo.Reports(TimeSpan, ReportData, TimeStamp) " +
"VALUES (@TimeSpan, @ReportData, @Date)";
SqlCommand cmd = new SqlCommand(sqlQuery, con);
cmd.Parameters.AddWithValue("@TimeSpan", span);
cmd.Parameters.AddWithValue("@ReportData", reportData);
cmd.Parameters.AddWithValue("@Date", timeStamp);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i != 0)
{
MessageBox.Show(i + " Data Saved");
}
}
catch (SqlException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
My connection string from app.config
<connectionStrings>
<add name="ReportManager.Properties.Settings.ReportsDBConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\App_Data\ReportsDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>