How to add scripts to C# package project

Forum for users of SQL Packager database archive utility

How to add scripts to C# package project

Postby ISRAEL » Wed Aug 10, 2011 5:51 pm

Hi there

I’m a newbie. I just want to know how to add a script to the C# Package project. I have some scripts that I have to run before the sync script produced by packager wizard.

Posts: 3
Joined: Mon May 23, 2011 4:05 pm

Postby james.billings » Thu Aug 11, 2011 7:33 pm

Thanks for your post.
The SQL that is created by packager is stored as resources in the C# project, and I don't think you can easily amend these. The generated application does support the /presql and /postsql commands though, so you can supply a .sql script as a commandline option when executing the built package.

If you wanted to incorporate the extra commands directly into your package when compiling, it's perhaps a little trickier and not something i've tried before.
A look at the project shows that the /presql and /postsql switches set a couple of properties in the PackageExecutor class. You'll see the Execute method in there calls:

Code: Select all
RunSQLFile(PreSqlFile, "Running pre-processing script")

The RunSQLFile method is responsible for loading the commands from the file and then passing them to the "ExecuteSQLCommand" method, so i'd look at implementing something around this area to suit your needs - for instance running some commands hard-coded into the app.

Hope that helps.
Posts: 1122
Joined: Wed Jun 16, 2010 10:10 am
Location: Red Gate

Return to SQL Packager Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests