Upload DBFile.mdf in App_Data to Azure - database

I have my ASP.NET MVC 3 project with a local database stored in /App_Data directory. This db is SQLExpress file (*-mdf).
I have my connection string working perfectly in my development CPU, the Connection String is:
data source=.\SQLEXPRESS;initial catalog=CFCBBSecurity;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MYFILE.mdf;User instance=true" providerName="System.Data.SqlClient"
When I upload it to Azure, using VS 2010, all files are in the server, but the application cannot access the Database.
What should I do, change or update?
Thanks in advance.

The problem is that you're referencing a local SQL instance (.\SQLEXPRESS, the 'dot' stands for localhost). I'm assuming you are running SQL Server 2005/2008/2012 Express on your machine and that's why this works locally.
But when you deploy your application to Windows Azure, there's no SQL Server installed on that Web Role/Worker Role/Web Site (this would be a bad idea anyways because Web/Worker Roles are not persistent!).
What you'll need to do is sign up for a 'cloud database' like SQL Azure and use that. Or you could host it yourself in a Windows Azure Virtual Machine (which is IaaS, but this involves more work).
If you're building an MVC 3 application I would suggest you simply start with SQL Azure. Here is a tutorial: Running ASP.NET MVC 3 Applications on Azure (note that this tutorial contains screenshots of the old portal).

Related

Why can Entity Framework code connect to SQL express in IIS Express but not on IIS?

I have a .Net core application that uses Entity Framework and SQL express running all running on the same machine.In debug mode from within Visual Studio 2019, i.e. IIS Express, I can read/write to the database no problem.
However, when I deploy to IIS also running on the same machine, any View which has a controller using Entity Framework returns a 404.
optionsBuilder.UseSqlServer("Server=.\\SQLExpress;Database=MyDB;Trusted_Connection=True;");
I'm assuming it's a privilages issue but using Trusted_Connection I'm not sure which account needs the privileges. Is it the admin account in windows 10? Do I need a special user account for ISS?
When I take away any code that uses EF, the 404 disappears so I'm certain it's a SQL server related issue.
Thanks,
Ian

WPF Application with SQL Server Express database deployment in production environment

I have a WPF application where I use Entity Framework for interacting with the database that is on SQL Server Express on my machine. I'm reasoning on small projects where data will not be huge and then I don't want to install SQL Server Express on client's machine for two reasons:
installation takes a long time
these projects must be executable on computers with low hardware specs (installation of SQL Server takes too much time)
I tried installing LocalDB on client machine, created default instance and started
The problems are two:
how to reconfigure app.config file making Entity Framework connecting to database? (in development environment connection string is SQL Server style)
where to put database files? (user's profile root?)
Am I following the correct way? I know only two way to do this, installing SQL Server Express or using LocalDB the may be a third way?
You can set up your app.config file as follows (just replace "C:\Database.mdf" with the full path to your database):
<connectionStrings>
<add name="NameOfConnectionString" connectionString="data source=(LocalDB)\v11.0;attachdbfilename=C:\Database.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
But with this you will end up having always the same static connection string.
Perhaps you want to store you database rather in some user folder.
This will get a sub folder of the users documents folder at runtime:
string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyAppsFolder");
If you want to deploy the local db to the users machine, you might want to create a installer project for this. See here
The alternative would be to install some version of SQL-Server on the client machine.
If it is possible that one the client site you will have more than one concurrent user you will have no other choice.
Difference between local db and SQL-Server express
If you need more information on the usage scenarios of local db and SQL-Server express, check out this question and answers.
This MSDN Site has also a bunch of information on LocalDB.

Cannot access LocalDB using SSMS when IIS is running

I have a web site app running on IIS 7.5 that access a LocalDb, all installed on same server.
Using SSMS, I can see the app db folder in the object explorer but when I try to expand it, I get an error saying that the database is not accessible. If I stop the web site in IIS then I can access it.
Is there a way that I can work on the database in SSMS simultaneously while the clients are accessing the web app ?
I log in the SSMS as administrator using Windows authentication. The web app log in as "IIS AppPool\AutoParkDemo" using the ApplicationPoolIdentity.
<connectionStrings>
<clear />
<add name="AutoPark" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=AutoParkDemo;AttachDbFilename=C:\AutoPark\Demo\Data\AutoParkDemo.mdf;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>
IIS server needs to have exclusive access to local db file, that is the main reason you can't access to database using SSMS.
In theory you could have read-only access to local db while IIS is running on background. I use often Visual Studio and IIS, and I can access local db while web server is running.
I believe SSMS needs write access to works with local db. This could be the reason why VS can read and SSMS not.
What I have found out is that each application that access LocalDB simultaneously, must have its own shared instance. There is a good tutorial about it on MS site, but the problem is that if there is no activity the shared instance stops and, although I read on Microsoft website that it will restart automatically, it didn't happen to me. After struggling for couple weeks, I decided to use the suggestion from other post on this site: When deploying to a web site with IIS, use SQLExpress instead. It now works perfectly.

Upload MVC4 site to server [duplicate]

This question already has answers here:
Uploading MVC site to server
(3 answers)
Closed 8 years ago.
I've developed website based on .NET MVC4.
I used simple membership .NET built in forms authentication.
I saw that the application uses some kind of MS database, but I don't really know what kind.
I want to upload my site to server and publish it.
Do I need to install some kind of database on the server? or I'll just need to upload the application and it will create the database on the server automatically?
Thanks.
The database created by default when using the MVC 4 Internet template is a SQL Server Express LocalDB, which is really intended for development and testing and not for deployment. Although I think some people do use it in production. If the correct components are on the server you are deploying to it will automatically create this database. If you look at the web.config generated by the template it looks something like this.
<add name="SimpleSecurityConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-SeedSimple-20130125152904;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-SeedSimple-20130125152904.mdf" providerName="System.Data.SqlClient" />
The name for the configuration string to use is defined in the WebSecurity.InitializeDatabaseConnection method as the first parameter. You will notice that the data source starts out with "(LocalDb)" which tells the runtime to use a LocalDB instance. I would recommend installing something like SQL Server Express or a full blown SQL Server instance on the server and changing the connection string to point to it instead for production.
You should explain more about state of your application database. At least you should let us see your working connection string(s).
If you have all your data in a single database - your own tables and the membership made tables - and your database is attached to a local database instance, you just need to generate a script from your current database and run that script on the database server of your web host.
Many scenarios exist according to the type of your application database (source) and the type of your web hosting database server (destination)...

Silverlight RIA query failing using authentication & impersonation

Database: Sql Server 2005
Webserver: IIS 5.0
IDE: Visual Studio 2010
I've created a Silverlight RIA application which will allow users of our intranet query one of our databases.
In the config I have set the authentication to windows and enabled impersonation.
In IIS i have disabled anonymous access and only enabled windows authentication.
This all works fine in my development environment and when running it from VS2010.
When i publish it to my local web server and connect to it from my local pc it works too.
However if i access the URL to the application on my local web server from another machine the application does not work. It gives the following error: "Load operation failed '[QueryName]'. Exception type 'System.ServiceModel.DomainServices.Client.DomainOperationException' was thrown.
The database sits on its own server. However i have the same database locally and if i change the connectionstring to local at the local version of that database it works fine.
IIS on my PC does not seem to forward requests to the SQL Server machine. As im running profiler to see what requests come in.
Any help on this would be greatly appreciated. Im sure im missing something.
Thanks
this was an issue was a classic double hop problem when using windows authentication. instead i used annoymous access on IIS and set the App Pool to an account that had access to the database on SQL Server

Resources