My asp.net is not accessing the .mdf
database file.
Local site works but when you attach a server application is down when you click on the button (ADD/MYORDERS) that writes in the database (visit a link). My site is hosted HERE
This is the connection config:
<add name="ConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
This is the code of the button
protected void IB_ADDPred0_Click(object sender, ImageClickEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into Orders (RoomNo, ProductNo, ProductName, Price) values (@RoomNo, @ProductNo, @ProductName, @Price)";
SqlCommand addOrder = new SqlCommand(insCmd, con);
addOrder.Parameters.AddWithValue("@RoomNo", computer_name[0].ToString());
addOrder.Parameters.AddWithValue("@ProductNo", ProductNo0.Text);
addOrder.Parameters.AddWithValue("@ProductName", NamePred0.Text);
addOrder.Parameters.AddWithValue("@Price", PricePred0.Text);
try
{
addOrder.ExecuteNonQuery();
con.Close();
}
catch (Exception er)
{
Response.Write("Error. Try again.");
}
}
Web application works normal when tested locally, but the server is the problems.
This is my web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<sessionState cookieless="true" regenerateExpiredSessionId="true" />
<customErrors mode="Off"/>
</system.web>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
The problem will solve at the if the make a web-hosting a new database and then Visual Studio just connect to it.
Download it from DDL current base and set of new to save time.
You probably use Windows hosting site. In parallels you can do it if the you create a new or transfer of old.