Sunday, February 19, 2012

Database question

Hello

I am using visual Basic 2005 express.

The program I am working on uses a database called DMGCollectionDatabase.mdf which will be held locally on the computer the program is installed on

When I publish my program as a cddvd install I get a setup file some other files and in the datasets folder I get a DMGCollectionDatabase.mdf.deploy file

if i install this program on a different computer than the one I used to build it it saves all the database information somewhere no clue where. what I need to be able to do is get the program to write to the DMGCollectionDatabase.mdf database so users can save this file with there information the dmg database will become portable my whole issue is how do I make this happen (I read one post that mentioned just using the .exe file and the database file in a folder this currently gives me an error)

If anyone could please assist me in this problem I would be greatly appriciative I am sorry if I seem a bit slow I am a self learner with visual Basic 2005 express I am about 3 months into things using vb2005 step by step and online help as references.

Hi Warren,

The issue is that SQL Server doesn't care what the *.mdf/*.ldf files are called, and by themselves, these files are worthless (unlike MSAccess)

What your setup will need to do is:

1. Verify that the target has a version of SQL Server installed

2. Create the DMGCollectionDatabase if it doens't already exist on the target sql instance, using the *.mdf & *.ldf file you mentioned. You do this via the sp_attach_db procedure. So, if your setup deploys the DMGCollectionDatabase.mdf and DMGCollectionDatabase.ldf file to C:\SomeApp\DMGCollectionDatabase.mdf, you would issue the following command on the target sql server instance:

exec sp_attach_db @.dbname = 'DMGCollectionDatabase', @.filename1 = 'C:\SomeApp\DMGCollectionDatabase.mdf', @.filename2 = 'C:\SomeApp\DMGCollectionDatabase.ldf'

And away you go...

Cheers,

Rob

|||

When I put this code into my formmain load "exec" gives me a declaration expected.

I placed the code above the first public class

|||

Hi Warren,

The code exec sp_attach_db @.dbname = 'DMGCollectionDatabase', @.filename1 = 'C:\SomeApp\DMGCollectionDatabase.mdf', @.filename2 = 'C:\SomeApp\DMGCollectionDatabase.ldf' is executing an SQL Server stored procedure - it needs to be executed against an sql server instance. Most setup/deployment tools allow you to shell a command, but if you're trying to do this from within VB, then you can execute the command in the context of a valid ado connection obejct, use dmo/smo or shell the command via osql.exe:

osql -E -i "exec sp_attach... etc"

For all available switches, have a look at osql in BOL. If you're using SQL2005, you should use the sqlcmd utility instead.

Cheers,

Rob

No comments:

Post a Comment