Showing posts with label sqlexpress. Show all posts
Showing posts with label sqlexpress. Show all posts

Monday, February 13, 2012

App_Data vs SQLEXPRESS performance?

Hi all,

Just wondering if there are any performance differences with having your database file in the App_Data folder vs having it directly on SQLEXPRESS.

Cheers,

Simon

Yes, but not much of one in most cases. If it's in App_Data with an autoattach, the database will be attached when it first accessed, which will delay the first request slightly. It will then stay attached for subsequent accesses. Eventually if there are no more accesses, the system will unattach it to conserve resources, I think it's between 5 and 30 minutes, but could be wrong.

In any case, the performance difference is slight, and the auto attaching and unattaching will help free memory and resources for the other applications that may be running on that server when the database isn't being used. Extremely nice for both infrequent database applications (Low resources), and high usage database applications (Since the database will always stay attached).

|||Great thanks for the detailed reply Motley! I think I'll migrate my db into the App_Data folder now =)

Cheers

APP_DATA directory

If I already have SQL2005 installed, can I create SQL express databases for distribution in my app, or do I need to install SQLExpress to run side-by-side?

I actually had SQLExpress originally but upsized it to the full version. Now I want to be able to create portable DBs with my application.

And if this is possible, how do I go about creating the DB?

Thanks!

You can refer to the upgraded SQL2005 instance just as you did to SQL Express. One thing to note is that if you have set "User Instance" attribute to true in your connection string, the connection to SQL2005 may fail with error message saying "User Instance can only be used with SQL Express..." (not exact, but something like this)|||

Thanks for the answer.. that helps on that error that I have received...

I think I might have been a bit unclear though...

On my local dev machine, I have the full SQL2005 version, but I want to create an application that can be distributed with a SQLExpress database in its app_data directory. This application will not require that the user attaches the .mdf through sql2005, but only that they have SQLexpress running as the DB will live locally in the APP_DATA directory.

Question is: Can I create the DB through my version and then just drop the .mdf in the APP_DATA directory and will it be compatible with SQLExpress?

Also, can I use a SQLExpress connection string / DB on my system during development without having to attach the DB to my sqlserver instance?

Sorry if my questions seem ignorant, but I am just trying to wrap my hands around the whole thing.

Thanks!

|||

NevermindBig SmileIf you do not want to attache the database file at run time, you have to use a database in your SQL Server. That's because what your application needs is not only a database file, but also needs a SQL Server instance. So if you want to switch between SQL Express and SQL 2005 (means different SQL instances) without attaching the database file at run time, you have to change your connection to SQL, and move database as well. There are some options you can choose to move database:

How to move database using detach/attach:

http://msdn2.microsoft.com/en-us/library/ms187858(d=ide).aspx

And copy database with backup/restore:

http://msdn2.microsoft.com/en-us/library/ms190436(d=ide).aspx

This article shows a good torturial for changing SQL connections in web application:

http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

Anyways, I recommend attaching the database file at run time--then you just need to change connection to SQL without moving databaseSmile