Deploy SQL Express in App_Data directory - asp.net

Despite using many sql databases before, I've never actually tried to develop an app with a database in the App_Data directory.
Until now!!
It's a small WCF service project, which has a sql express 2008 r2 database.
Working in VS there are no problems, I thought it would be as easy as deploying to a server (win 2008 with sql 2008 r2 installed) and it would just work. But it would appear not.
In the web.config, the connection string which uses |Data Directory| in the connection string.
I read here that |Data Directory| only works in VS, but looking at other articles on the web that doesn't seem to be the case.
I have (for the sake of this) given everyone modify rights on the app_data dir on the server.
I deployed using the package feature in VS 2010.
Thx
S

This problem was related to the application pool account in IIS not having permissions on the SQL Express instance.

Related

SQL Server Express and SQL Server Compact Edition

I've just built my first Umbraco site and now I want to hand it over for deployment on a web server. However, I built the site on my local machine using Web Matrix, which uses a SQL Server Compact Edition database, which is represented in a .sdf file.
I was a bit uneasy about whether this would be much use to the person I'm passing the site to (they have a number of Umbraco based sites running on this server using SQL Server) - so I installed SQL Server Express and migrated the database from Compact Edition to Express. However (again), I can't seem to find any way of exporting the full database to a file which can then by imported into a database on the web server.
A couple of points I guess - first, is the Compact Edition .sdf file actually enough for someone to take and import a database into SQL Server Standard? Failing that, how would I export the database from SQL Server Express to a file which could be used for this purpose?
Thanks in advance - this is my first foray into .net development so I'm grateful for any help!
You could just give the SQL CE database (.sdf) to the person who manages the web server. The SQL CE database can be run by default on a .NET webserver.
If, for some reason, you want to migrate it to SQL Server, you can do this through Web Matrix (http://www.microsoft.com/web/)
When you have already converted the SQL CE database to SQL Server, you can:
make a backup through the SQL Server Management Studio tool and restore the backup on the web server
or you can use the SQL Server Management Studio tool to script the database to a .sql file which can be executed on the web server
I prefer the first option.

Running asp.NET application on a local computer for testing purposes

I developed a web application for some small company. It connects to an SQL database created in Microsoft SQL server Managment studio 2008. Now they would like to test this app on a local computer before they put it on a server.
My question is, what are all the things I need to make this app work on a random computer running Win with no Visual Studio or SQL server installed?
Thanks for your help.
EDIT: They want to run it on a local computer only.
maybe Microsoft Web Platform Installer 3.0 can help you out.
http://www.microsoft.com/web/downloads/platform.aspx
Install .Net version you are using. It might already be there.
Install/configure IIS
Install SQL Server Express
Your db connection string obviously need to be changed to the local
sql server connection in web.config
Because it is a simple app, just copy the entire app (except proj
files, .cs, .vb files) to that computer
For one, point the connection string at SQL Server on a staging server. The whole idea of testing is to have the same environment as the production server.

ASP.NET User/Role Management in VS2010 - skipping over the SQL Express version and going straight to SQL Server 2008 R2

As I'm learning the ins and outs of ASP.NET user management, I've learned that the default in VS is for it to use a SQL Server Express .mdf file for the data it needs to save. This won't help me for when I deploy my site, as I'm running SQL Server 2008 R2 on my IIS 7.5 server. I know that I can run a command line tool to automatically create the db tables necessary for user management, and will do that on my development machine, but how do I tell my existing, in development code in VS to ignore the existing Express .mdf file and look at the newly created db tables?
Simply update your Web.Config to set up the role provider and the database connection string:
http://weblogs.asp.net/scottgu/archive/2006/11/20/common-gotcha-don-t-forget-to-clear-when-adding-providers.aspx
http://www.codersbarn.com/post/2008/02/24/ASPNET-20-Guest-Book-Admin-Part-II.aspx
Also, Scott Mitchell's Membership and Roles tutorial series is the most comprehensive I've seen:
http://weblogs.asp.net/scottgu/archive/2006/05/07/ASP.NET-2.0-Membership-and-Roles-Tutorial-Series.aspx

What's the difference between the database inside App_Data folder vs connecting to SQL Server?

I'm new to .NET and while starting to learn ASP .NET MVC2 framework I see that you can create a .mdf file inside the App_Data folder and connect to it or you can connect to a SQL Server.
What is the difference between these to methods of interacting with a database? What are the advantages/disadvantages of one over the other?
The "MDF in the App_Data" folder works for web site and web apps, and it works only with SQL Server Express (2005, 2008, 2008 R2). This is the version that's typically installed along with Visual Studio, and which works fine as a dev environment.
SQL Server Express has a few limitations on
number of CPU used (1)
max. size of a database (4 GB for 2005/2008, 10 GB for 2008 R2)
max. amount of RAM used (max. 1 GB)
and more. It's a great and free way to get into SQL Server development.
If you need production level SQL Server, then you're probably going to use a full version - Web, Workgroup, Standard, Enterprise or any of the highest level DataCenter editions.
There's a pretty comprehensive Compare SQL Server 2008 R2 Editions page up at Microsoft - go check it out!
The programming experience should be identical, too - it's really just a question of the ADO.NET connection string (and whether or not you need to have a locally installed SQL Server Express instance present).
The database file format is totally identical, so you can absolutely start with a .mdf file in your App_Data folder, and later move "up" to a full edition of SQL Server - simply attach your MDF file to your server instance, and now use that database. Works seamlessly.

SQL server won't open DB created by Visual Studio

I've built an ASP.Net site in Visual Studio, and created the DB inside it (the .mdf file is in the APP_data folder).
Now, when I want to deploy in the customer site, I think about maintaining the DB without open Visual Studio, and by using the SQL Server Express tools (back up etc.).
I've searched how to do this, and learned that I should attach the .mdf file to sql server.
I've tried to do this and failed!
The error is: Unable to open the physical file "< .mdf >". Operating system error 5: "5(failed to retrieve text for this error. Reason: 15105)". (Microsoft SQL Server, Error: 5120)
Google didn't helped me to solve the problem.
Now I have 2 options:
1. To give up and deploy the site in the current situation where the DB is an .mdf file and ASP.Net can connect to it by the SQL server express compact (in the proccess).
To extract all the data (I need to think how...) and import it to new DB, this time in SQL Server DB.
Wat would you recommend doing?
Thank you in advance.
If on Windows Vista or higher, try opening SQL Server Management Studio by right clicking and saying "Run as Administrator". As Mitch mentioned maybe it is just a permissions issue. Then try attaching to the database.
Error 5 is usually permissions related. Do you have permissions to access the file in it's location?
If you've created it in Visual Studio, it's most likely an Express database. SQL Server does not support "user mode" database connections which SQL Server Express use. Despite sharing a name, they are two fairly distinctive and different technologies.
To view the contents of an SQL Express database (ie- created in Visual Studio) I just use the Visual Studio server explorer.

Resources