Attach Database vs Server Connection

MartinaL

Active member
Joined
Jun 13, 2006
Messages
30
Programming Experience
1-3
VB.Net Windows Application, what is the difference and which is better to use;

1. Attach MSSQL database
2. SQL Server Connection
 
If you attach a database file then you're able to do all the work of creating it in the development environment. Then you just distribute it with your app and the connection string will take care of the rest.

If you want to use a database installed on the server itself then you're going to have to install it there when you install your app. That's not a big deal but it is extra work.

Note that not all SQL Server installations will allow you to attach an external file though.

Having said all this, there is no difference in your code between how the two methods are handled. As far as your code is cnoncerned you're connection to SQL Server and that's it. The only difference is the connection string.
 
When this is deployed the server where the application will be will only have SQL 2005 MSDE (or express i think it is called now), so in your opinion would I be better to just attach the database to the app rather then add the database to the SQL 2005 Express Server and then connect to it from the windows app?
 
Whether it's for Express or not is not really important. The issue is whether you are allowed to attach external files to the server. If I'm not mistaken that requires that the server allow User instances. As long as that option is set then you should be fine, and creating and distributing an MDF file is certainly easier for the developer. It means that the database is not immediately accessible to the DBA though, so they may prefer a database actually on the server. There are different approaches available because they both have pros and cons.
 
pro's an con's

it's pros and cons - apostrophes are never used when pluralising

It may depend on the target audience too - are you developing this app for exclusive use on the same network as which it will be developed, or will it be distributed and sold?

If the user has a requirement to do something, you can guarantee they wont want it done how you've done it. Do some research into your target market and find out how they perver their database servers configured, if you are developing multi-user system.. If the usual notion is that their servers dont allow attaching of your proposed files, then go the other way, and make them some canned scripts to create the schema internally. There is probably nothing stopping you offering both solutions and a changed config file if the connectionstring is different.
 
Quite so cjard. In fact, you could even prompt the user for their preferred arrangement during setup and then either install or create a database as required and then write the appropriate connection string to the config file. Automated is good.
 
Okay so say I choose to attach it, and click yes to copy to the project.

So once it is installed and all is good, when changes need to be made to this database, do I then attach this database file to SQL Server and make the changes and copy it back?
 
No. The whole point of attaching the database is that then you are using that database. Any changes you make are made to that database and no other. SQL Server is an application and by attaching your MDF file you've told SQL Server to use that file as a data file. You talk to SQL Server via ADO.NET and it does what you tell it to do to the data file, i.e. your MDF file.
 
Ok in my vb.net windows application created in VS 2005 i have had the database installed on remote server and have a connection string to it.

I have tried now installing the application on the clients pc's and attaching the database to their SQL Server and then changing the Dataset connection string to point to this new database location but the system seems to die and the dataset can not see the database on the new server??
 
Back
Top