CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

A nice thing about Sql Server 2005 Express and RANU

There are some new features around SQL Server Express 2005 (SSE) which allow you to treat your database just like a file. You can add the .MDF file to your project and then when you go to deploy your app it travels with it like a file so you don't have to worry about setting up a database on a server. This is similar to Access but with the power of SQL Server.  I believe this is how RANU (run as normal user) is supposed to work. Each user on the machine gets their own instance of SQL Express.  The way RANU works is that it looks in the exe's current folder for the .MDF file. When you debug and build your app in VS the exe is actually run from a subfolder so VS has to copy the .MDF to the same location. This requires you to put the .MDF in the project so that the project system knows to copy the file on a build. So the "short" answer is that there will be one copy to put it into your project folder, and then another copy to the build location on build or debug. There is a Copy to Output Directory property on the file which allows you to specific if you want to do the copy everytime or just when the .mdf file in the project changes.  So at runtime if I have a 1 GB database it is going to get copied around at that timeHowever, you can turn off this functionality. This is also specific to the designtime features. Runtime will work against an absolute path so you can avoid the copies if desired. It is expected that most databases won't be that large so it works pretty well for getting started with the feature.  Thanks to Eric on the Visual Basic Data Team at MS for the information on RANU! 



Comments

Raymond Lewallen said:

Alex, got this information back from the data team over at MS:

I asked them: "Also, with VS2005 and Sql Server Express 2005, you can attach an .MDF
file to a project and deploy your app so travels with it like a file
so you don't have to worry about setting up a database on a server.
Does this mean SSE will not be installed on the server in order to
access the .MDF file, and all access goes through an ADO provider? No
SSE has to be installed, kind of like Access?"

They responded with: "SSE must be installed under the instance name expected by the application. You can attached the .mdf to the Full SQL version, if you do this, then there will be an exclusive lock on that mdf file and you to detach it before you can use it in SSE again. Currently SQLClient provider for SSE scenarios. You can use the OLE DB provider to attach the mdf for the full SQL server."
# April 20, 2005 12:53 PM

Alex Kazovic said:

Rlewallen, thanks for taking the time to ask the question.

My interpretation of the answer is that although the .MDF file will be deployed on the new machine SSE will ned to be installed seperately (unless SQL Server is already installed there).
# April 20, 2005 1:02 PM

SergioTarrillo (supersergioman@hotmail.com) said:

I have the *.sql for Pubs and Northwind, with this don't have problem. But AdventureDB, is un *.mdf y *.ldf file, and I cann't attach this in my SQLExpress, is there some code make this?
# July 7, 2005 1:55 PM

Anil said:

what if we need to connect to Crystal report, where we need to give the connection string with servername and other stuff.

How do tackle this at the time of deployment.

If you have solution do let me know at anilmane@hotmail.com

# May 19, 2008 12:47 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!