I am developing an ASP.NET MVC website, which I want to host on Azure Websites. While in development, I have been using an MDF file in my App_Data directory with a connection string looking like this:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyApp;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyApp.mdf;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
To try it out on Azure, I was hoping I could leave this connection string as is, and simply FTP my MyApp.mdf into the App_Data folder on Azure, since it is all set up with the example data I want to use. However, when I tried to access my site, I ran into the following error:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 52 - Unable to locate a LocalDB
installation. Verify that SQL Server Express is properly installed and
that the LocalDB feature is enabled.)
My question is, is there a way I can run my Azure website connecting to an MDF file in my App_Data folder, or am I forced to use an Azure SQL database?
You can't use an .mdf file in App_Data, but you aren't forced to SQL Azure -- you can use SQL Server Compact. Deployment from LocalDB to Compact is easy if you are using Code First Migrations; otherwise you will have to migrate to SQL Server Compact before you deploy. If you decide to go with Compact you'll have to make sure the database engine gets deployed, and you can find instructions for that in this tutorial:
http://www.asp.net/mvc/tutorials/deployment/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12
You'll have to use SQL Azure to use the Websites/Cloud Service features.
If you haven't already you'll probably want to have a look at web.config transformations with web deploy to ease the publishing experience.
http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.aspx
You can import your data into the SQL Azure DB via the management tools or if you're using SQL Server 2012 you can import/export data via the portal.
Related
I am trying to publishing a ASP.NET MVC application that has db connection to a local sql server.
I want to publish this application along with db connection into a domain that should be available publicly, could you please help me with the steps necessary for the implementation
The current solution has 5 projects with one project as start up and has a db connection to local sql server, I do have access to Azure but not sure how to publish in azure
I have created a simple ASP.NET Core MVC application using EF Core and SQL Server. On the Windows development machine it is using localdb. I am trying to deploy to Azure App Service (Linux). I have created an Azure SQL database. Deploying from Visual Studio 2019, I have set the database as a dependency. In the publish profile settings I have selected the Azure SQL connection string for the database context I am using. I have also checked the EF Migrations and on deployment the script successfully created the tables for the application. I can connect to Azure SQL and see the tables. However when I run the deployed application and try a database operation I get: PlatformNotSupportedException: LocalDB is not supported on this platform
I can see from the docs various ways to set the connection string but I would like to know what the publish wizard in Visual Studio 2019 is trying to do and why it is not working? I'm also unclear where the password is stored. In the publish profile the password seems to be in the connection string as plain text, not good. I'd like to know how to get this right for production.
Update I have fixed this for the moment by following the steps in the Linux tutorial, using the Azure CLI and running the following command:
az webapp config connection-string set --resource-group [myResourceGroup] --name [app name] --settings MyDbConnection='[connection-string]' --connection-string-type SQLServer
I am not sure of the security of this approach and plan to investigate further.
The publish wizard simply handles the database creation/migration for you, it doesn't modify your project, as that's 1) not its purpose and 2) it can't make the configuration decision for you (i.e. use appsettings, environment variables, etc.)
You need to provide the connection string in production via configuration, just as in development. Since you're deploying to an Azure App Service, the most logical place for that would be to the App Settings in the Azure. These will be loaded in via environment variables. Simply specify the same key you're using in development and specify the production database target there.
I am trying to publish a VS2017 web app to a godaddy domain with authentication on a remote SQL server. The app works fine when run from the Visual Studio environment. I can log in, register, etc and see the data on my SQL Server. When deployed I get ::
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
Fixed - I discovered that the web.config file on the domain server did not get updated with the proper connection string.
Until last week, I developed with SQL Server 2008 non-R2 and my ASP.NET MVC web application worked fine in the Azure Compute Emulator. It establishes a database connection while running.
After switching to SQL Server 2008 R2 (deinstalled the non-R2 verson before), my web application can't connect to the database anymore when running in the Compute Emulator.
Interesting: When I start my application outside of the Azure Compute Emulator, it works!
The exception:
System.Data.SqlClient.SqlException was unhandled by user code
Message=Cannot open database "X" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Any ideas? Thanks!
I guess your connection string is with "Integrated Security=True" (or SSPI). Your old server was configured to grand access to the target DataBase for user "Netword Service", while your new R2 installation isn't.
Moreover, when you run your app under Compute Emulator, it uses IIS to run your web role, thus, the default app pool identity (Network Service). However when you run your application without the Cloud Project (Compute Emulator) it uses the Casini (AKA Web Development Server), which runs under the account used for Visual Studio (guess elevated version of your user account). And because your user account does have access to the dabase, your application also has.
I highly suggest drop off any "integrated security" connection strings, and use against SQL Server users when developing Windows Azure applications, that target cloud deployment. SQL Azure only supports SQL Server Authenticatin/Authorization.
I had the same problem, but after removing "Integrated Security=True" from my connection string in web.config the mvc-app could not connect either, this time because of an Entity-Framework error.
But fortunately this workaround finally solved my problem!
I built this app with Web Developer Express 2010 using SQL Server Express 2008. I downloaded mdf/log files from my server to my local and attached them as a database with SQL 2005 compatibility.
I'm now trying to publish to my production server. The server is using SQL Express 2005 and Windows Server Web. I tried to change out the web.config connectionstring, but I'm getting an "Unable to load the specified metadata resource" error. I 'm also a newbie/hack.
Here's a look at my production string:
<add name="ProductionEntities" connectionString="metadata=res://*/Production.csdl|res://*/Production.ssdl|res://*/Production.msl;provider=System.Data.SqlClient;provider connection string="Data Source=Production\SQLEXPRESS;Initial Catalog=ProductionCatalog;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
Here's a look at my dev string:
<add name="DevelopmentEntities" connectionString="metadata=res://*/Models.Development.csdl|res://*/Models.Development.ssdl|res://*/Models.Development.msl;provider=System.Data.SqlClient;provider connection string="Data Source=Development\SQLEXPRESS;Initial Catalog=DevelopmentCatalog;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /></connectionStrings>
I'm hoping someone can help point me in the right direction.
Thanks, I love you guys
-Joe
The metadata portion of your production connection string should not be different than the development connection string. The res: prefix means that the entity famework will be looking for CSDL, SSDL, and MSDL files in resources that are baked into the binary assemblies that you're deploying. These resource files are generate from your edmx file and they don't change between debug and release builds. So just copy the meta data portion of the connection string from development to production.
remove Integrated Security=True from connection string.