embedding /PRESQL & /POSTSQL
rbennet8
Posts: 74
Other than a .bat file, is it possible to embed the /presql & /postsql with the compiled executable? I would like to be able to employee just one executable and at most the two SQL scripts.
Comments
This is smething that I thought about, basically being able to put custom SQL into the package as an an additional embedded resource. The only way I could come up with, after lots of consultation, was to disassemble the executable, embed the SQL script as a resource, and recompile it.
The level of complication necessary to do this resulted in a simpler solution of the /presql and /postsql arguments to get the functionality out there on a shorter timescale and to avoid complications.
/presql
/postsql
/makedatabase
presql
postsql
makedatabase
All flags and switches need to be easily found in the help.
Now, back to the original post. I add custom SQL to every package. I add a version check TSQL script to the first resx file. I add a cleanup TSQL script to the last resx file. Then I build a new executable.
These features were added at the late minute so the documentation hadn't been updated. If you run the package and click the 'more info' button, then the 'Command-line options' tab, you will see the usage.
Otherwise, it's okay to tell packager to create a c# project, add an embedded resource that's a SQL file, and run that SQL file using Packager's ExecuteSql method in the code.
Note that trying to add anything onto the Package's existing resource in the project is asking for trouble! The resource is an 'executionblock' object and not a plain SQL resource.
That is a feature supported in the Visual Studio Environment. You can add a new file to the project, make it a plain text file, then change the compile type to 'Embedded Resource' in the file's properties. You can put some SQL code in this file. To read the'file' (remember after the compile it's an array of bytes inside the assembly!) back inside the project's code, you can code up a resource reader function to return the resource as a string:
I also found that I can replace the string.empty with my SQL file name in the packageexecutor.cs file for m_presqlfile. Since these are unique for each executable, it works quite well for our needs.
m_PreSqlFile=string.empty;
m_PreSqlFile="presql_pd0008.sql";