How to use a Visual Studio sql deployment script in a windows installer - sql

We've used a Visual Studio database project to manage our database schema. What we would like to is include .sql output of a database deployment as part of our products installer which is being created in InstallShield.
However when we add the sql script to the InstallShield project and run the installer, the installer fails to run the script. We get an OLEDB error complaining about the :setvar(s), although I could edit the sql script manually and fix it this isn't really a long term solution.

Garbage In Garbage Out. InstallShield just reads the scripts and executes it against an OLEDB connection. You can tell it On Error Abort, On Error Goto Next Statement or On Error Goto Next Script. Other then that it is what it is. If your SQL has problems they need to be fixed.
InstallShield can do search and replace processing on your SQL. Without a sample of your SQL it's difficult to say exactly what to do but take a look at:
Using InstallScript Text Substitution to Dynamically Replace Strings in SQL Scripts

Related

Better sql lite gives error for the code written in migration file

Better sql lite gives error and stops executing further code written in .sql file for the migration. due to which we might have to perform\write manual code.
For Example
you have table x in db file.
you add column through migration .sql file which is not available in table x.
run exe, column gets added.
closing the exe
run exe again
Now you will find error for the column already exists and stop execution further for .sql content.
I found some issues like it also not supports 'IF NOT EXIST' etc. may I know the reason as I'm not much familiar with the Database things.
here is which I have used for the database and it's helper packages manager.
https://www.npmjs.com/package/better-sqlite3
https://www.npmjs.com/package/better-sqlite3-helper
Thank you for helping hand in advance.

Cannot open a Script Task, but only one specific SSIS package, any suggestions please?

For only one particular SSIS package (v. 2005) I am getting the following error when trying to open the script task...
TITLE: Microsoft Visual Studio
Cannot show the editor for this task.
ADDITIONAL INFORMATION:
The operation could not be completed. (Microsoft.VisualBasic.Vsa.DT)
BUTTONS:
OK
I need to get into this to be able to edit it, also I am in the process of upgrading it to 2014. Once upgraded I can get in, but there is no code, so assume the upgrade is not working as it=self cannot see the code within.
I have tried other machines - same problem.
I have tried other packages - they work fine - even in the same solution.
I have tried a few resets found on the net/re-installs - same problem.
Clearly its something to do with this specific package only, but I am stumped.
I would expect to be able to open the Script task like any other, and be able to edit it. I would also expect the upgrade to work and contain the code.
If you want to read the Script Task code, open the package file (.dtsx) using a text editor (Notepad++), and search for the Script Task code, copy the Script Task code and recreate the script and paste the code within the Script editor.
If you have a problem with Script Tasks in visual studio 2005, then copy the code to an external file, upgrade the package to 2014 then paste the code inside the Script Task (since it will be empty after upgrade)

What is the best way to manage "non-SQL Server" SQL objects within Visual Studio 2010?

Visual Studio has a Database Project for Sql Server. This has a number of advantages: it hosts configuration settings, and database objects in one place. The .sql files are part of the regular .NET solutions - visible in the Solution Explorer and editable in Visual Studio. And they have a mechanism for generating a deployment script. With each individual database object in it's own file, the tracking of changes and source control is greatly simplified.
Has anyone had any success with using Database Projects with "non-SQL Server" databases? We use Sybase - which uses T-SQL and is very similar to SQL Server so I'm hopeful.
Or is there an alternative approach? I guess I could use a standard project (.csproj) and call a custom commandline application as part of the post-build to convert the .sql files into a deployment script.
Any ideas would be welcome.
Thanks
OK, I'll answer my own question.
I added all of our SQL objects to their own .sql files within a Visual Studio .dbproj project. However, minor syntactic incompatibilities between the Sybase version of RAISERROR and the Microsoft version of RAISERROR caused the validation code built into Visual Studio to get unhappy. The problem with the database project was that this actually caused a compilation error - which basically made it into a show-stopper.
So I scrapped that idea and added the .sql files to a standard .csproj project file. I then implemented some custom code that would load all of the .sql files, and aggregate them into a deployment script when invoked. I added a call to the custom code to the post build of the .csproj file so that whenever it was compiled - it would output a deployment script - which works like a dream with our build server.
In order to get some of the benefits of the .dbproj, I looked into writing a full SQL parser, but was quickly discouraged by some of the posts on SO. Instead I did some rudimmentary parsing with regex - which got me a few cool features without a lot of effort:
The code could detect dependencies between the various .sql files, and add them to the deployment script in the correct order to avoid sysdepends warnings.
Where there were no dependencies, objects were ordered based on the object type (stored procedure, function, grant statement, etc) and then by name so that the resulting script was always ordered the same - which is very important if you need to diff two versions of the script.
The deployment script can figure out some of the required permissions, so I don't need to keep track of all of the GRANT statements.
Stored procedures that are in the database but not in the script can be dropped automatically - so I don't need to keep track of what state each database is in - we just run the script and everything is in the correct state.
We have a few stored procedures that our automated tests call that shouldn't be deployed. The code can detect these and include them in a Debug build and exclude them in a Release build.
The custom code also generates a diff script that determines what changes the deployment script will make to a database and prints them out. This allows the person who is running the script to get an idea of what it will do. For example, the diff script might tell them that no changes will be made - so they don't need to run the deployment script at all - which is kind of handy if it saves them logging in at 3am to take a database offline and take backups etc.
So the end result is that all of my SQL objects are in separate files making them easy to work with in Visual Studio and manage under source control. For the first time since I started this job, I can look at the history in source control and tell what files have been changed (before this we had one enormous .sql file with absolutely everything in it).

DB Pro (data dude) and Wix3 SqlExtension

I'm attempting to use Wix to create a database during install. I have my database setup with the Db Pro Visual Studio SKU (Data Dude as it's sometimes referred). However, the output seems to be only consumable by sqlcmd.exe since it uses specific syntax in it (variable references like :setenv and $(FOO)).
I'm trying to use the wix sqlextension which apparently isn't using sqlcmd.exe (I haven't investigated what data access technology it's using just yet.
Does anyone know if there is a way to use the output of data dude natively in the wix sqlextension or alternately if there is something that will take the sqlcmd output and translate it into the runtime sql needed to execute against the sql server?
Please note that the ultimate goal is to fully integrate wix into our build system so I am looking for an automated approach.
If you have created the package using Visual Studio DBPro it is best to use VSDBCMD.exe for the DB deployment. The benefits of this is that the VSDBCMD.exe always figures out the differential of the destination to the source and creates a delta script which can be run from the same command line. You just need to provide /action:Deploy.
There is a blog post that covers calling the sqlcmd.exe utility from WiX 3 at http://neilsleightholm.blogspot.com/2008/08/executing-sqlcmd-from-wix.html

Transact SQL How to to do?

I need to generate a SQL update command in a *.sdf file.
The *.sdf file is deployed using Visual studio. I am looking to generate a script which fills in a table the maximum number of records which is about 2MBytes.
any ideas for how I can do this i.e. connect remotely to the database and script filling in the database with a dummy record? Examples and deployment would be fab :-)
I presume you have a database project in Visual Studio.
In a database project, the post-deployment script is executed in Command mode. You can use the following syntax to execute any commands that you want executed.
:r "filepath\filename.ext"
Visual Studio Team Systems for Database Developers will do this for you.