Github check in local database - c#

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.

Related

Create setup file from C# project with SQL server database in Visual Studio 2015

I want to create a setup file from a C# project in Visual Studio 2015 that attaches a SQL server database, and I want to run that setup file on another system and run without Visual Studio and SQL server
You are have two solutions
You should develop your application with SQL express on .NET framework or after develop with SQL Server change connection string from SQL Server to SQL express and rebuild it, be sure you create initialize DbContext class to set some data for run your application at first time with base and default data. [Such as application users and rolls and groups].
You should develop your application with dependency injection pattern [Microsoft Unity, IoC] then modify or replace one interface to change your developed application database.
Then Right click on project in solution explorer and publish it and give to customer.
The customer server has to run some kind of SQL Server if you want the SQL data to be accessed somehow. One thing you can do is to deploy your C# project with Visual Studio, export all needed tables (including their data if you want that) from whatever server you are using (for example MySQL) into a .sql file and pack everything, including instructions on how to install the sql server and your application, into a zip file and ship it to your customer.
What I do with my website application is, that I include a .bat that fetches everything from my git repository, deploys my web application on an existing IIS-Server on the current computer (with 'aspnet_compiler -f -c -u -errorstack -v /web -p "source directory" -d "target directory"' and 'iisreset /noforce') and automatically imports the SQL tables to an existing MySQL Server (with mysql --host=localhost --user=user --password=password --database=database < Backup.sql).
Sorry for that general answer, but you're question really wasn't that precise.
If you want to create a setup of your project then,
Click on Build on the top of visual studio tab and then click on Publish "yourprojectname" click on it and your setup file will be ready.
Hope this helps you
Use LocalDB,
(no need to at least open sql server management studio)
When you create Setup file add prerequisite
.net framework version
sql server (2012 -2019) express localdb
Add connection string correctly!
So from what I can gather you are looking for an easy way to distribute your database schema to clients, is that correct? If so then I don't see how you could intend to run the setup without SQL Server (without VS is fine though).
Assuming my assumption is the case then I think you need to think about a solution that will handle schema upgrades as your project develops, in which case it's essential that you move to Database Projects in Visual Studio as it will handle upgrading the schema automatically, and allow you to run change scripts for the things it can't do automatically (like when you've changed a column type or removed a column etc).
Here are some links to get you started:
Working with Database Projects (MSDN)
Introducting Database Projects for Visual Studio (youtube)
Using the knowledge that CSPROJ files are just MSBUILD scripts at the end of the day you can now publish the database project during whatever your installation/upgrade system is using msbuild which is included in the .NET framework i.e. you don't need Visual Studio.
This is by far the most robust and reliable way of dealing with database deployment. I would advise staying well clear of automated tools like Redgate, they do a great job for small projects that maybe get used in an office etc but for professional software development you need more guarantees and control.
You can try this, with Octopus deploy.
Or, you can try with Code First migration
Have you already existing database, or development starts now?

C#: Create a DB using sql file in setup project

I am building a desktop application where it uses a local database file (.mdf). Since I was developing it on my machine I used SQL Management 2008 R2 SP2. Then I sent it out to others for feedback. But unfortunately they were not able to use it as they didn't have SP2 installed.
So, as a resolution, I want to include a sql file that would run while installing the application. I was wondering if someone could direct me how to do so.
What I have and what I think should be done is:
- Main Project (includes forms and classes - I have this working already)
- Setup Project (includes msi file that checks database existence and runs sql file accordingly - I need help on this)
I suggest you using wix to create the msi.
You know, you can no longer create setup project using visual studio (Version 2012 above). It has been removed completely.
So you should consider going in WIX (Windows Intaller XML) direction.
If you like the idea here is the quick and easy solution:
http://www.codeproject.com/Articles/331368/WIXDataBase
http://wix.tramontana.co.hu/tutorial/sql/creating-a-database
But its completely up to you to think about the alternatives.

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.

How to version SQL Server schema using VS 2005?

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.

autorun methods

I have developed a small desktop application in c#(using windows forms). For this project I need mysql, MySql.Data.dll and some property files...
I am ready with my project but I need to burn it on a disk(with Autorun express).
when I run that cd
It should ask me to check whether the system has mysql installed in it or not,if not installed already then it should install now in the specified location
run some database scripts to generate database and relationships and constraints
and finally it should copy my .exe file on to the hard disk (specified location).
Thanks,
srini.
It sounds like you're trying to use autorun to kick off an installer. Take a look at the built-in Installer project in Visual Studio, or take a look at WiX.
"Check whether the system has mysql"
To validate whether the machine you
has MySql, you'll need to define
what you're looking for. As for most
products, you can find them in the
registry. I'm not sure where MySql
puts that info.
"Run some database scripts"
You can kick off a custom action that will
properly install the database.
"Copy my .exe file"
Specify where you want the installer to put your
executable and other binaries
(MySql.Data.dll).
NSIS is another good choice for an installer. I used that one pretty extensively, and am using WiX on my current project mostly just to try a different approach. The one included with Vistual Studio 2005 is very buggy, but I have not tried the included ones for Visual Studio 2008 and later.
NSIS and WiX follow very different approaches for creating the installer file. You may find one or the other easier for you to understand. Both seem to have pretty active communities that will help if you get stuck (or ask here of course).

Categories