Ruben Misrahi
Ruben Misrahi

Reputation: 51

Publishing to Azure From Visual Studio 2015 with an MSSql using PublishSettings

I can publish to Azure with an MS SQL DB, which works locally fine.

I have my DB working with https and locally it works fine. After I publish the app works fine except when I try to access any table of the DB. I get below error

Cannot find the object dbo.CarType because it does not exist or you do not have permissions.

Before that in Azure I've created an App and have linked to it an MSSql. After I do this, I get the Published Settings (below, pwd masked), which I then Import when publishing. BTW, I've used code-first migrations, but before publishing I did reset the migrations to start with a clean slate then just added a migration: add-migration Initial.

.PublishShettings file:

<publishData>
   <publishProfile profileName="CrJbApp - Web Deploy" publishMethod="MSDeploy" publishUrl="crjbapp.scm.azurewebsites.net:443" msdeploySite="CrJbApp" userName="$CrJbApp" userPWD="Jrdab2E8xl4HidsdaRLS6oR5rPEtFPG8cHd20SYl4WtqFjymdc5qgf6sCsrC" destinationAppUrl="http://crjbapp.azurewebsites.net" SQLServerDBConnectionString="Data Source=tcp:g2ojj5kj5y.database.windows.net,1433;Initial Catalog=CrJbDb;User Id=XXXXXXX@g2ojj5kj5y;Password=XXXXXX;" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100">
      <databases>
         <add name="DefaultConnection" connectionString="Data Source=tcp:g2ojj5kj5y.database.windows.net,1433;Initial Catalog=CrJbDb;User Id=XXXXXXX@g2ojj5kj5y;Password=XXXXXXX;" providerName="System.Data.SqlClient" type="Sql" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100" />
      </databases>
   </publishProfile>
   <publishProfile profileName="CrJbApp - FTP" publishMethod="FTP" publishUrl="ftp://waws-prod-am2-051.ftp.azurewebsites.windows.net/site/wwwroot" ftpPassiveMode="True" userName="CrJbApp\$CrJbApp" userPWD="Jrdab2E8xl4HidsdaRLS6oR5rPEtFPG8cHd20SYl4WtqFjymdc5qgf6sCsrC" destinationAppUrl="http://crjbapp.azurewebsites.net" SQLServerDBConnectionString="Data Source=tcp:g2ojj5kj5y.database.windows.net,1433;Initial Catalog=CrJbDb;User Id=XXXXXXXX@g2ojj5kj5y;Password=XXXXXXXX;" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100">
      <databases>
         <add name="DefaultConnection" connectionString="Data Source=tcp:g2ojj5kj5y.database.windows.net,1433;Initial Catalog=CrJbDb;User Id=XXXXXXX@g2ojj5kj5y;Password=XXXXXXXX;" providerName="System.Data.SqlClient" type="Sql" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100" />
      </databases>
   </publishProfile>
</publishData>

Upvotes: 0

Views: 160

Answers (2)

Ruben Misrahi
Ruben Misrahi

Reputation: 51

Thanks for the help. I could not add a "useful" point because I have only 11 in reputation score (a lackey, so to speak).

But I found what my problem was: I had to do 2 things: - Remove the Migrations (not the folder, just the migrations). - Add this line in Migrations/Configuration.cs on the Configuration() constructor: AutomaticMigrationDataLossAllowed = true; - When publishing, check the option to run migrations, so the Seed method is run.

If anyone tells me how to add useful points to the answer given I'll appreciate it.

Upvotes: 0

chief7
chief7

Reputation: 14383

This doesn't directly answer your EF Migrations questions but is an alternative solution. We tried migrations but decided to use Database Projects and DACPACs to deploy instead. This works exceptionally well for us. You should try it.

http://dotnetcatch.com/2016/02/10/deploying-a-database-project-with-msdeploy/

Upvotes: 0

Related Questions