SQLTeam.com | Weblogs | Forums


SSMS import data tier process allows for the selection of a folder to place the .mdf and .ldf file. I need to write a vb project that has that ability, i have coded to create the bacpac file, and import the bacpac file to connect to the sqlserver instance, i need to be able to tell the program where to put the .mdf and .ldf files
thank you in advance

From a T-SQL perspective, it boils down to this statement:

(NAME = <logical_data_name>, FILENAME='<drive_letter:\path_to_data_file\data_filename.mdf>'
,SIZE=<size>, FILEGROWTH=<file_growth_DO_NOT_USE_PERCENT>)
(NAME = <logical_transaction_log_name>, FILENAME='<drive_letter:\path_to_transaction_log_file\log_filename.mdf>'
,SIZE=<size>, FILEGROWTH=<file_growth_DO_NOT_USE_PERCENT>)

All the items in angle brackets are variables for your DB name, file names, paths, etc. Do not include angle brackets in the statement. You can construct that statement as a string, with the correct parameter replacements, and then execute it as a SQL command through ADO, ADO.Net, whatever DB library you're using.

Also take a look at sqlpackage.exe. It's a command-line utility for doing all things possible with DACPAC and BACPAC files:

There's a lot of options to deploy a database, but there are parameters for DB name, file location, etc., that you can execute from a command-line batch file, or via a Shell command from VB. Depending on the VB needed it might end up easier for what you're trying to do.

I've used sqlpackage.exe from command scripts and once you get the hang of it, it's awesome.