How to version SQL Server schema using VS 2005? - c#

I am new to C# programming and am coming to it most recently from working with Ruby on Rails. In RoR, I am used to being able to write schema migrations for the database. I would like to be able to do something similar for my C#/SQLServer projects.
Does such a tool exist for the VS 2005 toolset?
Would it be wise to use RoR migrations with SQL Server directly outside of VS 2005? In other words, I would handle all schema versioning using ActiveRecord:Migration from Rails but nothing else.
If I do handle migrations outside of C# and VS 2005 with another tool, is RoR ActiveRecord:Migration the best thing to use or is there something which is a better fit?

There's no built in way of doing this without the Database Edition of VS Team Edition. We use a NANT script similar to this and date the migration files with a date similar to how Ruby does it.
http://www.bottleit.com.au/blog/post/Continuous-database-integration.aspx

I have been happy with DBDeploy.NET for handling our database versioning. My current project uses C# + SQL 2008. DBDeploy is not integrated into Visual Studio but I suppose you could make it happen with some custom external tool entries in the IDE.
There are other tools out there that certainly work. I am not familiar with Ruby ActiveRecord:Migration but if you are already experienced in using this particular tool why not stick with it? As far as database versioning / migrations inside of Visual Studio I believe you will need to upgrade to the Database Professional Edition (extra cost for this version last I checked).
In summary, I would go with what you know. Most of the free tools for DB versioning are still somewhat half-baked at present IMHO. If you would like more information on DBDeploy.NET you can read up on it from the original project it was ported from here - http://dbdeploy.com/ Also, keep in mind that the DBDeploy tool is cross-platform (supports many DB systems, not just SQL Server & Oracle) and open-source.

For distributing application my favorite approach is actually one built in-house: Version Control and your Database.
I use the database extended properties to store the current on-disk deployed schema version, and then run an internal upgrade array that maintains a map between on-disk version => upgrade script to next version. At start-up, the app runs the steps in the upgrade array until the on-disk version matches the current app version. So an upgrade goes through all intermediate versions. Deploying a new site ( a new location) goes through every schema version, sometimes creating and dropping object no longer used. This may seem weird, but in the end the application can be deployed over any previously released version. If a client has a schema from 3 years ago everyone forgot what it contains, the app knows how to bring it up to date, always, which is great.
I favor this approach over diff compare tools (eg. VS DB project integration) because is testable and offer much better control over the exact steps taken on any upgrade. Diff tools do all sort of questionable actions, like copying tables and renaming, which doe snot work for deployments measuring +1TB (which my app has to deal with).
If the data size you expect is reasonable small (<100 Gb) I'd consider diff based tools. VS DB project deployment based on vsdbcmd works fine in such conditions. Also, if your deployment target is only one location (ie a web app where there is only one target, the web site db), then ability to upgrade any previous version looses it's appeal.

Try DBSourceTools. http://dbsourcetools.codeplex.com
Its open source, and specifically designed to help developers version control databases.

Related

Github check in local database

I'm using Visual Studio Enterprise 2015, along with the Github plugin.
For a assignment I have to use C# with a database, which isn't a problem within VS. But, I want to check the local database into the repository, so I can work on the project on multiple computers.
I'm the only one who will use this repository (it's private). There won't be changes apart from my own.
I know it's not really meant to do this, but I really would like to remain working with local databases for simplicity purposes.
I've found this answer on the topic, but I'm not sure what he's trying to say.
I do really thank you for asking such a beautiful question that opened my mind . And I found this blog and it really explains how to do this job . And I realized that I will be needing this :) . Please check out the synchronizing-a-mysql-database-with-git-and-git-hooks Hope this helps .
When you use Visual Studio together with SQL Server Developer tools you can have your database schema and initial data scripted out as a Visual Studio project. You'd then use the Visual Studio project to define what the database looks like and you can then use the project to create a SQL Server LocalDB or SQL Server Express database on demand when you restore your project. You can sync the schema between your local database and the Visual Studio project. And commit the difference to git.
Alternatively you could use something like Entity Framework to define your database schema or use Entity Framework Code First annotations to map your object model to a database schema. Combined with Entity Framework Migrations and Entity Framework Data Initializers you can instruct you application to rebuild the database at startup time should it be missing.
Using Git pre-commit hooks on Windows is not the easiest thing to setup and Visual Studio 2012-2015 won't execute your hooks, you'd have to do all your git operations through the commandline for these hooks to start working. Visual Studio 2017 uses the git.exe commandline tool and should be able to run your hooks, though support for hooks is still limited if you're using a normal command shell instead of a bash shell (linux shell). Most hooks are implemented as Linux shell scripts or other scripting languages that are not always fully supported on Windows.
Depending on the file size, you could always just commit the database file itself, the binary files. Though git generally doesn't like binaries, nothing prevents you from committing the latest state and transferring it to another machine this way.
I usually but the instructions to build the database into the repository, either a .sql file or a script to execute the commands needed to restore the database.
A database like sqlite is stored in only one file, that you could easily put in your git repository.
If your looking for more concrete ideas, you might want to share what database your working with.

How To make setup file that contains C# application and sql server

I want to build a setup file that contain windows form application that is connected to sql server how can I do that? I want to put the .net framework and sql server in the setup package how can I do that? do I need sql server or sql express in this case? I want to create the database in the installation process how can I do this? I want to check If the requirements are already installed how can I do this? hw can I improve the security of the program from stealing?? please help thanks
note my English language not good enough Smile | :)
That is a lot more than one question, and not easy to answer all at once. Anyway, assuming you're using Visual Studio 2012, you can try creating a new Install Shield project (below).
(It might be easier to help you once you've tried something, and have got a more specific question/problem)
For my projects I use Inno Setup. It lets you customize all aspects of the installer - add/remove different screens, set conditions for installing different files, for example you can check out whether SQL server is installed and install it only if it is not through scripting. Take a look at the FAQ page for more information about the features this tool offers.
There's also a sample Inno Setup file at CodePlex, that should get the job done. I haven't tried it though, so I cannot guarantee whether it works fine or not.
If you want to have installer for tomorrow, than good choice will be WIX (http://wix.sourceforge.net/). It is easy to understand and have a possibility of checking installed frameworks and OS version.
If you wish to have Framework msi installer inside yours, than you can check Wix Bootsrapper. But as far as I know it has poor flexibility to setup install steps. For this propose you can combine Wix with other for example NSIS. You can create application installer by using Wix and Bootsrapper application, which will contains your application MSI and Framework MSI, by using NSIS.
To create database during installation you also can use WIX. You need to create database generation plan, which will contain queries for creating database. This generation plan can be executed as part of the installation process (http://wix.tramontana.co.hu/tutorial/sql/creating-a-database). It is good choice wile you don't need additional information from user. In other case you will need to create custom UI.
From my experience with built in Visual Studio install tools, they're all horrible.
I highly recommend Advanced Installer. It's a very powerful tool to create installers and patches for your software. It should have all the features you need in the free version, including checking for prerequisites such as .NET Framework on the user's machine, and installing things when needed.

What's the standard practice to upgrade a sqlite database from .NET code in an installer

I have a .NET application that uses a sqlite database. In the latest release we need to upgrade the schema. I am wondering what is the standard practice to upgrade a sqlite database from .NET code in an installer? We use Wix with custom actions implemented in a .NET assembly.
Thanks,
Tools such as WiX and InstallShield only have native support for SQL ( WiX, InstallShield ), Oracle ( InstallShield ) and MySQL ( InstallShield - Requires MySQL Connect ). There is nothing native in MSI and no other off the shelf solutions for installers that I'm aware of.
You can certainly roll your own ( hopefully data driven ) custom actions for dealing with this but if it was me I'd consider implementing your database servicing in your application layer. This way your application is more fault tolerant and self servicing without needing the help of an installer.
For example if a customer was to upgrade your installer then restore an older version of your database, your application would be able to self upgrade it to the new schema.
An approach would be creating a diff sql script - one updating existing schema by adding, updating or removing parts that may be changed - and execute it against outdated database.
That should be enough, since it'll change original schema with the new one.
By the way, what about the data? If database schema has changed, maybe you'll need to migrate previous database date.
If I'm not wrong, you want to do that from code, and this allows you to create a backup of the outdated database. After creating such backup, you should perform a post-schema-update action in order to migrate data, and finally you can (or not) remove the backup.

Making a setup for C#/SQL app

this is my first post in stackoverflow, I've always checked this site by searching in google, so I decided to join it myself! I hope to be useful to others
I'm a 3d developer (DirectX), but recently I've started making an SMS gateway using C# and SQL Express, now I'm going to create a setup file for my project (which uses .NET 3.5), what are my options? I've heard that VS 2008 can make setup, is there any sample? how can I include SQL express in my setup app?
also I've downloaded Install Shield 2010 which has a built-in support for VS 2008, I want to make my setup in a way that it detects SQL on target system and if it finds SQL already installed, doesn't try to install it again (the same rule can be applied for .NET), what are my options? how can I make such a setup file?
thanks
With Microsoft's Visual Studio, there is an inbuilt Setup Template which you can use.
Click Once
For your scenario you should take a look at Adding Click once Custom Prerequisites.
Setup And Deployment Application
For your scenario you should take a look at the Walk-through.
Or as you mentioned you have InstallSheild 2010 then:
Install Shield Wizard
Take a look at this Walk-through with Limited Edition
As for SQL Server i think you can usually go as far as SQL Server Compact Edition. (For anything greater you may need to Inform User to install it himself)
I have no personal experience with it, but SQL Server 2008 Compact might be good for this. It is an embedded solution so so you don't actually need to install a server. Alternatively you could look at SQLite, which has native .NET implementations (google for "sqlite .net").

How to make a setup installer? For asp.net mvc 2.0, cmd line applications and webservices

I am wondering how can I make a setup project for each of these projects
Asp.net mvc 2.0
C# cmd line
Application C# web-service
I am using VS 2010 ultimate and I know that I can use the the free edition of install shield for at least the cmd line application. I am not sure about the other 2. I also know about the setup project that you can use. I just need a lot more than the basics so I am not sure how to make either one do these things.
So here is some criteria that each of my setups should be able to do.
Asp.net mvc 2.0 criteria
free (I really don't want to pay for an installer - you can list them just so I am aware of them).
Terms of service
Ability to force a user to setup certain settings. Like connection string, smtp settings. So they should be able to type it in through the setup wizard and the web.config should be updated based on this.
When it installs the stuff it should all be .dlls for all the C# code.
C# cmd line criteria
All criteria as above
I am not sure if this has to be done in the code but I have a html file that contains a template for a message. The path to this file is in the web.config so I a person needs to set this path each time they install it. I tried to do this in code but I could not figure out how to make it find the right path in development and the right path in production. It seems like If you run in VS the path is different.
Web-service
Pretty much everything I covered in the first 2 ones.
Thanks
If I were you, I would choose WiX as a platform for your installers for all these applications. Some reasoning behind this:
it is XML-based, that is, friendly to source control, diffing and merging
it has rich set of tools for most of scenarios you might need (harvesting lots of files, creating upgrades and patches, creating multi-lingual installs, etc.)
it is free and open source
it is production-ready (at least, version 3.0 - later versions are still in beta)
it is used by Microsoft to create installations for such products like MS Office
it has rich community at wix-users#lists.sourceforge.net and StackOverflow
it integrates into the VS like a charm
it is friendly to build engines like NAnt and MSBuild
VS setup project is not my choice because:
it is very limited in set of features-
it encourages bad practices like Installer classes
finally, it was retired by Microsoft
I'm not familiar with InstallShield Limited edition, though.
Hope this overview will help you finding the best option for your case.

Categories