Deploying C# application with SQL database - c#

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.

Related

Deploy Database From C# To Sql Azure

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.

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.

.Net Application Installation 2012 with database

I have built a Windows Forms application using Visual Studio 2012 and MSSQL 2008. I need to deploy this project using InstallShield Limited Edition.
While running this application on my pc, it does nto work well when I use the following connection string or .//SQLEXPRESS.
I need the installer to find the exe file of the application on other uer's pc with the database file. Where do I need to put my database files in the deployment files folder? What should my connection string be?
i use .//SQLEXPRESS it doesnt work as well
DO NOT use .//SQLEXPRESS as datasource name in the connection string.
Recommended way is to menthion Instance Name if your application is to be deployed in different environments(especially OS). I ran into trouble when I had the Datasource as .dot which worked in Win 7 not in WinXP. Either one of the following approach works fine.
(local)\SqlInstanceName
(ComputerName)\SqlInstanceName Ex: CD-SJHONES\SQLINSTNACE
In certain cases i had to include the computer name, So during the application deployment i get the computer name and update the connection string accordingly.
where i need to put my database files in deployment files and folder
and what should be my connection string
Connection string
I have already answered connection string releated question above.
Database files
What do you mean by database file. how database is created in the client machine ? do you create a database during application deployment or users manually create it with script ? There is nothing to worry about the database fine as long as your application have right connection string to point to your database.
Application files and folders
Again this doesn't really matter where application files and folders resides in the client machine. It's upto the users to decide where he/she likes to install the application.
You cannot install from backup. Also in your scenario, you should force end user t install Sql Express, what If it has already installed. So You need considering , scripting of entire database. You can create another exe / look for option in Installshield to execute that Script incase the database server is found else, force user to download the Sql Sever Express or Embedd it into setup and execute the script over there. But that will make your Setup Size more than 100's of MB.

Setup SQL Server for database made in c#

I have a problem, I made a nice application in C# with a SQL database, now I wanted to install that application on another pc but it doesn't connect to database file. Is there a nice way that I can install that database and connect to it with only changing connection string in my program. Is there any way that I can access the database through network? I tried to find some tutorial but without luck..
I would suggest you to append the database file (which ever it is) to your project. So it will be located inside the project`s folder.
But before Publishing the application, change the connection string, instead of a full path use |DataDirectory| . This is an example:
//from
#"....Database=C:\MyProject\MyDataBase.mdf;...";
//change to to:
#"....Database=|DataDirectory|\MyDataBase.mdf;...";
This way you will not have issues with connection string.
But dont forget to ADD the database file to your project (incuse it in it).
You need SQL Server Express to connect to database files. You have this installed automatically with visual studio, but another computer may not have it. Make sure that another computer has SQL server installed.

service based database

I have one problem with service base database, I have used it in one of my application but I dont know if user who'll use it need to have something installed to be able to run application (like you need to have installed NET framework for c# applications)
Note: This is windows application
It depends on what database engine you're using. SQL Server/SQL Express/Oracle/MySQL require you install the application on the machine before it'll work. databases engines like SQLite and Firebird are just Dll's, so you can include then in your project.
If the file is an MDF that's a SQL Server file - you need to install SQL server, or SQL express.
You can include it with your app and do it silently:
http://social.msdn.microsoft.com/forums/en-US/sqlsetupandupgrade/thread/7180e4dc-5c1e-4501-83d7-6882abb1f04e/
You will need to install the relevant database engine with the correct service name, and create the database and relevant objects on installation.

Categories

Resources