Trying to INSERT in db but keep getting Keyword not supported: 'metadata'
I've read all the postings that have to do with this but can't figure it
out. I imagine my problem is in the web.config. Any help would really be
appreciated. Still getting the hang of .NET
Here's the error:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.ArgumentException: Keyword not supported:
'metadata'.
Source Error:
Line 20: {
Line 21: string connString =
System.Configuration.ConfigurationManager.ConnectionStrings["CateringAuthorizationEntities"].ConnectionString;
Line 22: SqlConnection conn = new SqlConnection(connString);
Line 23: string sql = "INSERT INTO tbBooking (BookingName) VALUES "
Line 24: + " (@BookingName)";
C# Code:
private void ExecuteInsert(string name)
{
string connString =
System.Configuration.ConfigurationManager.ConnectionStrings["CateringAuthorizationEntities"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string sql = "INSERT INTO tbBooking (BookingName) VALUES "
+ " (@BookingName)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[1];
//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param[0] = new SqlParameter("@BookingName",
System.Data.SqlDbType.VarChar, 50);
param[0].Value = name;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = System.Data.CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void BtnCatering_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
//call the method to execute insert to the database
ExecuteInsert(BookingName.Text);
Response.Write("Record was successfully added!");
}
}
Web.Config:
<connectionStrings>
<add name="ApplicationServices" connectionString="data
source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User
Instance=true" providerName="System.Data.SqlClient"/>
<add name="CateringAuthorizationEntities"
connectionString="metadata=res://*/App_Code.CateringAuthorization.csdl|res://*/App_Code.CateringAuthorization.ssdl|res://*/App_Code.CateringAuthorization.msl;provider=System.Data.SqlClient;provider
connection string="data source=xxxxxx;initial
catalog=CateringAuthorization;integrated
security=True;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient"/>
No comments:
Post a Comment