Deploy Database From C# To Sql Azure - c#

I am looking for some .Net code sample or any .Net library using which I would like to build a small tool to automate my activities like I can connect to Sql Azure . Once I get connected I would like to deploy my database(mdf & ldf file) to the remote sql azure server .Once the deployment gets completed I would like to create a login and respective user for the deployed databases and assign them required permissions respective to databases . Currently I am doing all these activities from Management Studio but I want to create a tool which would does all these activities on a click of button . I would define a step by step template for all my activities and this tool will execute each step .
I tried looking for libraries but didn't find anything useful . Now I have no idea where to start so Please help me as I am a novice to these type of stuffs.

Visual Studio does all of this via its Database Project template. It will either update the target directly, or generate a script which you can execute. Also remember the OSQL command line version of Management Studio for doing batch script execution.

The Best Solution in this case will be to use Visual Studio Release Management.
In Release Manager you can create workflow to execute Deployment Tasks. If you have a Database project which produces a DACPAC, you can use Azure SQL Database Deployment task in Release Manager to deploy the Database to SQL Azure. More Details can be found here
https://www.visualstudio.com/en-us/docs/release/examples/azure/azure-web-apps-and-sql-db

With Azure, you can't just copy the local mdf file. If you need to migrate schema and data, the easiest way to migration from local Sql Server to Azure, is to export the database to a BACPAC file, and then import that file back into azure. migrate bacppac file.
After you've create your database and populated, use the Azure portal or Sql Management studio to create additional logins.

Related

How to attach my Microsoft SQL Server 2016 database to installshield project in Visual Studio 2015?

I'm coding a C# Console Application that connects to a database and runs some queries where my database Engine is Microsoft SQL Server 2016 and I code in Visual Studio 2015. I have already installed and activated InstallShield Limited Edition on my visual studio and I'm able to make an installation(setup) file for my C# Console Application.
I don't want to to install Sql Server on my customer's PC and attach the database to that manually, instead I want to give everything in an installation file that includes .Net framework 4.5 and my database. The first part(.Net Framework) is done by InstallShield easily, but I don't know how to attach my database to the installation file.
Please explain how to do this and if any other version of InstallShield(Express, Professional or Premier) is needed let me know and explain the steps in that version.
Note that I want to give the installation file to the customer and make every feature of the app function well after he/she installs the program without needing to do anything manually.
Sql server 2016 cannot be installed automatically as it needs to be configured by the user, he must set the instance names, permissions and so on, which makes it unusable for your scenario.
What you need to use is Sql Server LocalDB, this is a subset of Sql Server Express for your concrete scenario, something which can be installed without the need of configuration and capable of attaching a database file also without user interaction.
You can find information about LocalDB here, as you see it can be downloaded as a .msi, in this way you can add this msi to your installshield project and chain it (more info on how to chain an installer here), it will not ask to the user about complex configurations, just a simple installer. To download the .msi you get the sql server express installer on your development machine and instruct it to download media and select the LocalDB package, that will give you the .msi.
Finally you will add the database file as part of your project files, then you only need to specify on the connection string the path to the file.

How to continuous delivery with Database SSDT c# VSTS EF6 Azure

I want to implement CI and CD for website with database (on Azure).
Tools:
SSDT (project database)
C#
VSTS (Visual studio team services)
EF6 (entity framework 6)
Azure SQL database
The aim is a full Continuous Delivery even with the database (Hardest part).
For the website, CD is pretty much easy with VSTS. But about the database, I can't find a clear way how to proceed.
So by some readings I plan to :
Use SSDT to manage the Database. VSTS build, use dacpac of the database projet to generate by itself by schema comparison to update the database. I'll just write sql script for data motion.
Use EF6 and "reverse POCO code first generator" link
To be 100% Continuous Delivery, I can't stop the service, even during database schema modification.
So I read that database update has to be compatible with previous deploiement (DAL of running website). So all database schema modification will be in to 2 steps, in two deliveries. The Second delivery can be only when the 1 step is delivered.
So rules should be
Rename a table is not allowed
Rename a column is not allowed
Add column
1 Step
Add column in SSDT with default value
Add property to entity class
2 Step
Remove default value on the database
Remove column
1 Step
Remove column on entity
Add default value by SSDT
2 Step
Remove column by SSDT
I'm pretty sur, that I'm reinventing the wheel, but I can't find a complet tutorial.
Am I on the good way ? Is there something out the box solution in microsoft world ? I'm ready to learn. Thank you
You can deploy database to azure through Azure SQL Database Deployment step/task in you build or release. Also, you can deploy your app to Azure through VSTS Build or release.
For example:
Add an Azure Resource Manager
Create a build definition on your VSTS
Add Visual Studio Build step to build database project and it will generate dacpac file.
Add Azure SQL Database Deployment step to deploy database to azure via dacpac file (step 3)
Add Visual Studio Build step to build your app project
(optional) Add Azure App Service Deploy step to deploy your app (web) if needed.
(optional) Go to trigger and check Continuous integration (CI) to queue build for each check-in
There is a related article (follow up its workflow, it uses Azure Classic, you could use Azure Resource Manager).

create setup for an app with MSSQL server at backend

I want to create a setup file for an application that uses the following tools and technologies:
Microsoft visuals studio 2013
MSSQL server 2012
and I have used winforms and C# to write the program.
My questions are:
If I want to deliver the application to customer without giving out the source code what technique or tool should I use?
How do i supply the database? Should I detach it? How do I provide the database with my application?
I'm assuming you need to deploy the application you've created with Visual Studio rather than deploy Visual Studio itself. In which case you have a variety of options depending on its destination.
You can just copy your executable and required dependencies to a destination without distributing your source. However, there are several tools out there that will subsequently disassemble your assemblies to reveal the source.
The Visual Studio website has a list of options for deploying applications. If you want a tradional Next -> Next -> Finish type of installation, I would suggest using InstallShield Limited Edition.
For SQL deployment it would depend on the Edition you have used and whether the server already exists at the destination. Additionally, it will depend on whether you only need to deploy the schema or populate the database too.
You can distribute SQL Server Express with your application. SQL Server Management Studio will allow you to generate a "CREATE DATABASE" script (right-click database -> Script database as -> CREATE to -> File) from your existing database that can be executed as part of the installation. Alternatively, consider a backup/restore approach as detailed in this article.

How To Deploy A Windows Application That Uses SQL Server (Standalone EXE)

I currently access & write data to/from text files but want to make a move over to SQL Server (Also not yet sure which version). Note: This is a Windows Desktop, Windows Forms Application.
My application uses a DB (Single user) & I want to deploy JUST the EXE file, no additional DB/Access tables etc (I want to use SQL Server rather than MSAccess anyway).
What would be the best way to install the tables of the DB onto my users machines? (I also don't want to use MSI installers etc, JUST an EXE file).
Assuming there is an instance of SQL Server available on the client, you could use my company's product BuildMaster to create this EXE for you. Once you've installed it you can:
Install the SQL Server extension (Admin > BuildMaster Extensions)
Create a new Standard Application
Select "Configuration > "Database Connections" from the application menubar
Register a new connection with a fresh SQL Server database
Initialize the database within BuildMaster
Visit "Configuration > "SQL Change Scripts" from the application menubar
Choose "Add Change Script" to upload the script file(s) you'd like to make an EXE from
Once saved, you can select "Download Deployment Tool", this will generate a standalone EXE with the script contained within it
This generated EXE can run with optional arguments (e.g. a custom connection string) as specified in the Using the Change Script Package documentation. Also note that it will only run the scripts one time against the target database. For more information about that, you can read the change script documentation.
Not surprisingly, this is how we deploy BuildMaster's database itself; the tool is contained within the installer as an embedded resource and then written to disk and executed by the installer.
SQL Server isn't designed to be embedded into applications. Consider using an embed-able SQL database such as SQLLite or SQL Server Compact. You can also use certain methods to install SQL Server Express with your application.

Deploying C# application with SQL database

I have developed a C# application with SQL database, now i want to package it with the database and deploy it on some other machine which does have sql installed. How should i go with it.
What should be the connectionstring for the project, currently i am using "initialcatalog".
Pls Help
I am not sure, if I understand the question well.
If this is a C# class library only, you can get the dll and deploy in the required application.
If this is a web application, you can either create a web deployment package or publish the site.
For SQL migration, you can used the database publishing wizard from microsoft.
http://www.microsoft.com/en-in/download/details.aspx?id=5498
I hope my answers helped you.
Make .bak file of your SQL database.
Publish c#.NET application.
In the folders where you programmed this application, you will find published setup of your application.
Complete wizard in that publish setup folder.
upload database backup file(.bak) where you want to install application.
In this way you can deploy your application.
there are some install maker tools like install shield, which you can make a setup for your application,
About your connection string if your sql server is on your local computer you should set the "DataSource = . "
somthing like this : "Data Source=.;Initial Catalog=yourDBName;User ID=sa;Password=1"
the dot means local computer.
to create your data base on the target computer you can right click on your database and select task\generateScript and follow the wizard to make your database script the run that script on the target computer.
It's a common practice to include mdf or sdf file directly in solution (at least that's how are a lot of MS examples like Northwind/AdventureWorks are done). So you need to detach your db and then simply reattach it to other db server. You can read more here http://goo.gl/0FV1N
You can create a set of SQL Scripts to build the database via T-SQL or you could create a script to attach a new database to the server using the MDF/LDF files you include with your project.
Examples:
C# use script to create database
http://support.microsoft.com/kb/307283
Regardless of how you do it, you'll first need to establish a connection to the SQL Server with rights to create a new database. You might want to prompt for these values during install or on the first launch of your program.

Categories

Resources