locked
Webconfig and updating EF on Host SQL server RRS feed

  • Question

  • User461852431 posted

    I’m building a booking system in ASP.NET, Entity Framework with SQL server in VS2012Express

    I’ve deployed the Pages on Webhost and SQL Server and it all works fine.

    Soon, it will go public and I will go on develop the system, to update the SQL server file I will use ‘SQL server management studio’ for creating new tables etc.

    Let’s say I’ve added some new tables to the Host SQL server then the Local EDModel is not yet updated with the new changes, then I have to do “update model from database”

    My thought was to make a new web.config file that debugs the local asp files but connects to Host SQL, so I can do the update but it doesn’t work, visual studio still debugs the with localDB.

    How do I update the Local EDModel from Host SQL server?

     

    <?xml version="1.0" encoding="utf-8"?>

     <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

    <connectionStrings>

    <add name="ConnectionStringSQL" connectionString="Data Source=HOSTSQLServeraddress;Initial Catalog=bokningslistan;Persist Security Info=True;User Id=*****;Password=*****;" providerName="System.Data.OleDb"

     xdt:Transform="Replace" xdt:Locator="Match(name)" />

    <add name="BokningslistanV3Entities" connectionString="metadata=res://*/Bokningslistan_EDModel.csdl|res://*/Bokningslistan_EDModel.ssdl|res://*/Bokningslistan_EDModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=HOSTSQLServeraddress;Persist Security Info=True;Initial Catalog=bokningslistan; User Id=*****;Password=*****;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient"

     xdt:Transform="Replace" xdt:Locator="Match(name)" />

    </connectionStrings>

      <system.web>

        <compilation xdt:Transform="RemoveAttributes(debug)" />

      </system.web>

    </configuration>

    Monday, November 11, 2013 6:15 PM

Answers

  • User-1454326058 posted

    Hi Tbeat,

    Thanks for your post!

    According to your description, I think you are using the EF DataBase first.

    Please check the value of connectionstring name in [Name].Context.cs file. (e.g. Model1.Context.cs)

    For example:

    public MessageInfoEntities()
                : base("name=MessageInfoEntities")
            {
            }

    Then find the connectionstring in the web.config file, such as:

    <add name="MessageInfoEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\v11.0;initial catalog=MessageInfo;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

    After that, please modify the connection string value, such as:

    Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;
    Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

    More information, please refer to: http://www.connectionstrings.com/sql-server/

    Note: Make sure, the TCP/IP has already been enabled in the Host SQL Server.

    Next, double click the Model1.edmx file=>right click the Model1.edmx[Diagram1]=>select Update Model from database.

    Please check the Tables in the Update Wizard whether they are in the host sql database.

    If it still use the local sql database, please try to remove the connectionstring in the web.config file. Then try again. (It will let you to select/create new connectionstring)

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 13, 2013 12:51 AM

All replies

  • User-1454326058 posted

    Hi Tbeat,

    Thanks for your post!

    According to your description, I think you are using the EF DataBase first.

    Please check the value of connectionstring name in [Name].Context.cs file. (e.g. Model1.Context.cs)

    For example:

    public MessageInfoEntities()
                : base("name=MessageInfoEntities")
            {
            }

    Then find the connectionstring in the web.config file, such as:

    <add name="MessageInfoEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\v11.0;initial catalog=MessageInfo;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

    After that, please modify the connection string value, such as:

    Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;
    Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

    More information, please refer to: http://www.connectionstrings.com/sql-server/

    Note: Make sure, the TCP/IP has already been enabled in the Host SQL Server.

    Next, double click the Model1.edmx file=>right click the Model1.edmx[Diagram1]=>select Update Model from database.

    Please check the Tables in the Update Wizard whether they are in the host sql database.

    If it still use the local sql database, please try to remove the connectionstring in the web.config file. Then try again. (It will let you to select/create new connectionstring)

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 13, 2013 12:51 AM
  • User461852431 posted

    Hi

    Yes it's working when modifying web.config file! 
    If I want to go back to local server again I modify it manually.

    Many thanks!

    Wednesday, November 13, 2013 7:20 AM