Today,I am going to show how to create setup file(.exe) with SQL Database in visual studio 2010.In our previous tutorial I have created a setup file(.exe) without including Database in Setup File.This method is purely different to the previous setup creation method ,But it is very easy .Remember one things ,when you install this setup to your desktop ,first install .NET Framework 4.0 or 4.5 in your machine otherwise it will give error.
There are some steps to create setup file with SQL Database, which are given below:Step 1 : First open your visual studio -->File -->New-->Project-->Select Windows Forms Application -->OK-->and drag and drop Label,TextBox & Button control on the Form from toolbox as shown below:
Note:-
If you are facing problem to Add .mdf file in your solution Explorer then read following links:-
Step 3 : Now Double click on Database.mdf file-->Add New Table as shown below:
Step 4 : Now Enter your table column name-->and press save button as shown below:
Step 5 : Now go left window of your visual studio-->click Data sources (if not available then click Data Button on top-->Click show Data sources)-->Add New Data source --> Select Data Source -->Next-->Select Dataset -->Next-->Choose connection string -->Next
Now continue with Next Button then you will see as shown below-->Next.
Step 6 : Now open Solution Explorer -->Add New Web Form --> drag and drop DataGridView control from toolbox-->and configure it as before.
Step 7 : Now open Solution Explore-->Right Click on Project -->Add New Reference-->.NET --> add Two Namespace as given below-->OK
- System.Configuration
- System.Configuration.install
Step 8 : Now Double Click on Submit and Show Table Data Button and write the following codes as given below.
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace winsetup
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["newConnectionString"].ConnectionString);
con.Open();
String str = "insert into student(Name,mobile,city) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
label4.Text = "Data has been successfully inserted";
}
private void button2_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
this.Hide();
frm2.Show();
}
}
}
Step 9 : Now open App.config file from Solution Explorer --> change name and add same code in your connection code as shown below:
Note:- Now i am going to create setup file with SQL Database as shown below .
Step 10 : Now open Solution Explorer -->Right click on the project -->Properties -->click publish Button From left window as shown below:
Step 11 : Now First Create New folder (mysetup) on your Desktop .
Step 12 : Now Click Publishing Folder Location --> Select Your Folder(mysetup) from Desktop as shown below-->click Open.
Step 13 : Now click Prerequisites Button-->Select following options as shown below-->OK.
Step 14 : Now click Options -->Write the required field as shown below-->OK
Step 15 : Now click Publish Wizard.. from bottom --> click Next as shown below.
Step 16 : Now proceed with Next Button --> click Finish .
Step 17 : Now click Publish Now Button from Bottom --> Your setup will be created in your Desktop folder (mysetup).
see it:
Step 18 : Now First install .NET Framework 4.0 or 4.5 in your system,If you are using visual studio 2010 or 2012.After that you can install this setup.It will take few minutes.
Step 19 : Now Double click on setup Icon on the Desktop .You will see.
Step 20 : Now Enter the required field and click Submit Button.You will see.
Step 21 : Now Click Show Table Data Button.You will see.
Step 22 : If you want you can create setup file in visual studio 2012 and visual studio 2013 also.
For More:-
- Ado.Net Application
- How to Build Real Form Filling application in asp.net like IBPS
- Xml Application
- E-Post System Project
- Take Print receipt in Windows Form Application
- oops concepts
- Data Integrity in Sql
- File Handling Real Application
- Overview of C#
- How to use WCF Services in asp.net application
- How to use different connection strings in asp.net
- Operator overloading in c#
- Web Forms controls
- How to use secure login page in asp.net with example
- How to Add and verify Captcha image in 3 tier architecture in asp.net
- How to use virtual keyboard in asp.net for security purpose
- How to implement hashing concepts in asp.net
- Learn complete .Net Interview Questions and answers for job seekers
Application Setup File
Application not formetted well this error occured. please solve it
ReplyDeletehi Tej Parikh ! when i have installed this setup on my system then it has not shown any error.i have shown installation on my desktop in above tutorials. pl follow each step very carefully again which is shown as tutorials.first install .net framework 4.0/4.5 in your system.then create setup and install them.it will work..
ReplyDeleteCan i create a setup file for a website?
ReplyDeleteif yes please tell me the procedure to build it otherwise what is the other option to do this?
yes, you can create web setup for website also.see it-
Deletehttp://4.bp.blogspot.com/-fs9rst_yaGw/Uo9fe5Zf_YI/AAAAAAAACOo/SZu0AzwMVLg/s1600/websetup.PNG
if i create a setup file for window desktop application after install the setup file on client machine . Then if i want to some changes in this application and i want to use install database file of client machine. how is possible ?
Deletehi, nice post but there is a problem that i could find the data in my table offcourse the data is displaying on second form but when i close the application then restart there is no data not even this data is stored in the database. could you please help me.
ReplyDeleteThanks in advance
you can improve the setup, before installing the setup check the .net version if its not 4/4.5 then tell user to download it
ReplyDeletehi, when i clik the save button their is not showing any connection error but data is not saved in table. plz help me
ReplyDeleteyes,, correct @Sukant
ReplyDeletehi RAMASHANKER !!
we can add the details to table and it is visible in gridview like this,
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["newConnectionString"].ConnectionString);
con.Open();
String str = "insert into student(name,roll,class) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
SqlCommand cmd = new SqlCommand(str, con);
int a=cmd.ExecuteNonQuery();
SqlDataAdapter ada = new SqlDataAdapter("SELECT *from student", con);
DataTable dt = new DataTable();
ada.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
if (a==1)
label7.Text = "Data has been successfully inserted";
else
label7.Text = "not inserted";
but when i go
server Explorer > show table data
and all values are NULL
:(
Please give me a solution.
cannot we setup a file directly with SQL database ?
Use this code instead of DataTable dt = new DataTable();,otherwise it will show null value.
Deleteada.Fill(dt);
dataGridView1.DataSource = dt;
Dataset ds = new Dataset();
ada.Fill(ds);
dataGridView1.DataSource = ds;
I am facing the same problem. Data is not reflected in database. It shows in the grid view but when we go to server explorer -> show table data the value is not reflected. Plz Help Soon
Deletehi akshay ! first tell me what error is showing....
Deletewell, this is what i did
DeleteSqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet mydataset;
string sql = null;
sql = "Select id,name,dates from temp";
con = new SqlConnection(connectionString);
con.Open();
cmd = new SqlCommand(sql, con);
da = new SqlDataAdapter();
da.SelectCommand = cmd;
mydataset = new DataSet();
da.Fill(mydataset, "data");
dataGridView1.DataSource = mydataset;
dataGridView1.DataMember = mydataset.Tables["data"].ToString();
label5.Text = "Data refreshed";
con.Close();
and now i have repeat what Akshay said before "It shows in the grid view but when we go to server explorer -> show table data the value is not reflected"
And see there is no error at all.
hi i want the exact conversion bit for a dot net application, can any you help me
ReplyDeleteIs this db is always attached with application on various systems? I mean this db will be a local copy whwrever I will install it right?
ReplyDeleteOk almost every thing is same in visual studio 2010 and visual studio 2012....
ReplyDeleteI follow your steps of
"How to create setup file(.exe) with Database in Visual studio 2010"
in visual studio 2012
But when i click on Publish wizard button...and after that when i click on Finish button.it gives me the following error.
Error 1 Cannot publish because a project failed to build
Error 2 Unable to copy file "App.config" to "bin\Debug\app.publish\Application Files\Finding Mac Address of the system_1_0_0_0\Finding Mac Address of the system.exe.config.deploy". The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. Finding Mac Address of the system
...please help me what is the problem
This is a problem with Visual Studio that can occur when you have add-ins installed. Instead of using the Publish button in the Publish tab, use Build/Publish from the menu on the top of Visual Studio.
DeleteIf you use the Publish button, it runs through the add-ins before doing the build (or something like that). If you use Build from the menu instead, it goes straight to msbuild and ignores any add-ins you have installed.
Hope this helps u..
hello sir. I have an error after the publish wizard the error is "Cannot publish because a project failed to build."
ReplyDeletePlz help me...
hi chetan, follow each steps carefully,some times it will happened.create new application ,don't use previous application to create the setup.it will definitely work,if any problem then you can contact me through Contact Me form.
Deletehello sir, thanx for reply. I solved the above issue. I have another query.
DeleteI want to set the installation path of the my setup file. sir tell me how to do that ? Also i want to know where is database is stored after completion of installation ?
Plz help me sir it's urgent. thnaxx..
Hello sir, Thanx for reply.. i solved the above issue. I have another query.
DeleteI want to set the installation path in setup file and also i want to know where is database is storing after the installation how can i take backup of database ?
sir plz help me it's urgent..
Thank you..
hi chetan,first create a folder on Your Desktop or any drive --> give that folder path (i have explained it in above tutorial)-->all database file(sql server) + application will stored in this folder --> when you install it any client machine---> all database is stored on installation path (your drive, where you install it c,d or other) ..
DeleteSir i already do the above process but it is not working. When i m seeing the path of the project it is "C:\Users\hp\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Chetan\setupfile". I want to install the setup in c drive and program files and also the database in that folder..
ReplyDeleteThank you.
hi RAMSHANKAR
ReplyDeleteI want to add framework to my setup file.
means when i click on setup file then first it check that there is framework installed on my machine or not...
nd if it is not installed then first it install that nd then my project will install.......................
plz help me
Hello sir,
ReplyDeleteI want to make setup file of my windows application ,I am using entity framework model,C#.NET,Winform ,Database I am using is sql server 2008,What is process of making setup file & setup should work anywhere .... ,I am getting JIT debugger error on installing & ruining application.
Please help me I am getting JIT debugger error....
hi suraj ! i have already mentioned 'How to create setup file with sql database' in above tutorial.follow each step and install .net framework 4.0/4.5 before creating the setup file. jit compiler error is coming because you have not create setup file correctly.
DeleteI have followed your above Information(Tutorial) for make setup for C# Windows Application which has database in
ReplyDeleteSQLExpress2008 but following error is occurred when i open that setup application
"Unhandled exception has occurred in your application.
An attempt to attach an auto-named database for file C:\Document and Setting\Rachit-41\LocalSettings\Apps\2.0\YBO9521P.Y3J\db\payrolldatabase.mdf failed.
A database with the same name exists, or specified file cannot be opened.,or it is located on UNC share."
hi Prajakta ! change your database name because one Database.mdf file is exist in your c dive.
Deletechange Database.mdf --> mydb.mdf or another name.then it will work.
I hope you can do this...
Sorry Sir But i have changed the database with another name like mydb1.mdf
Deletebut it shows also above error
"An attempt to attach an auto-named database for file D:\emppayrollsystems\1 may setup\PayrollManagementSystem\PayrollManagementSystem\mydb1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
Hi Prajakta ! First read below link .it may be helpful to solve this problem.
Deletehttp://www.msdotnet.co.in/2013/04/how-to-solve-problem-to-add-sql.html
read this carefully. first create new application and perform this steps.if it will work.then perform this steps in your original project.
i have changed database name like mydbpay.mdf. but it gives error when i build the program code.
DeleteIt shows following error:-
"An attempt to attach an auto-named database for file D:\emppayrollsystems\1 may setup\PayrollManagementSystem\PayrollManagementSystem\mydb1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
What can i do for this?
i have a problem that i am creating printable application so please tell me how to design winform so that that page data should be show on a4 size paper bottom.....
ReplyDeletehi Ankur ! Read below link.It will be helpful for you......
Deletehttp://www.msdotnet.co.in/2012/06/how-can-take-print-receipt-and-save.html
Thank You for this tutorial. It was GREAT!!!
ReplyDeleteGood Work ...!
ReplyDeleteSir When i m seeing the path of the project it is "C:\Users\hp\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Chetan\setupfile". I want to install the setup in c drive and program files and also the database in that folder.. How to backup data from this setup after installation
ReplyDeletePls help me Thank you.
Is there any idea to hide our database files which is stored in C drive....to be safe from unknown user.
ReplyDeleteSetup is not asking for installation path ???
ReplyDeletePlease Help !!!
Sir RAMASHANKER VERMA when i insert data into student tbl then object reference not set to an instance of object error is genrate,how to solve it??
ReplyDeletehi ,
Deletecheck your connection string codes whether you are inserting values in same columns which are created in your table or don't change order of your column and data types,see it carefully.this error basically comes due to change order of values or data types in your connection string.
sir its connection string problem,connection method set on form load,when form is run that error is generate object reference not set to an instance of object ,please help
Deletewill this exe file work on client machine?which have not sql server
ReplyDeleteyes , you can install it on other system .
Deleteok thanx sir
ReplyDeleteHello sir,
ReplyDeleteYour tutorial was really helpful and easy to understand so that I was able to create my first setup using DB. Now I am developing a C# windows Application which has a third party Database that is sql server management studio 2008.Will it be possible to create a setup for it in the similar way described above with its database having .dbo extension instead of .mdf? pleas help me.
Hi Sir,
ReplyDeleteMy file.exe created properly.It working fine on my machine but when i am Installing on client machine database module not working
please reply me
I am using an oracle sql database with my website in visual studio 2012. While creating the .exe file..how is the database getting copied to the client's machine? Is it automatically attaching the database along with the .exe file?
ReplyDeletehow to add installation wizard,agreement,icon in this type of exe???
ReplyDeleteand why this exe is not displayed in program files??
my app.config code is
ReplyDeletebut in my code file throwing error object reference is null and if use
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
is throw error and use another way
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
its working
my App.config file code is as bellow but i am getting error I explain bellow
ReplyDeletebut in my code file throwing error object reference is null and if use
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
is throw error and use another way
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
its working
ReplyDeletewhen i publish my application this will showing this error.
To enable 'Download prerequisites from the same location as my application' in the Prerequisites dialog box, you must download file 'DotNetFX45\dotNetFx45_Full_x86_x64.exe' for item 'Microsoft .NET Framework 4.5 (x86 and x64)' to your local machine. For more information, see http://go.microsoft.com/fwlink/?LinkId=239883.
please help me to solve this problem.
Hi Ankit,
DeleteRead step 18, first install latest .net framework 4.0 or 4.5 or 4.5.1 on your system, then it will work...
hi ramshanker sir
ReplyDeleteI check my folder and sqlexpress is not showing in my folder
please help me to rectify the issue
hi ramshankar sir
ReplyDeletein my folder that is on desktop sqlexpress2008 is not showing
please help
hi sir
ReplyDeletewhen i trying to install this exe on other machine
getting an sql connection error
i installed .net framework 4.0 on that machine
please help
Can I implement backup and restore in desktop application, that can be work on any desktop machine, please help me
ReplyDelete. I develop one Invoice application, but backup and restore not work with local database it find sql server & database
How to attach database in set up file
ReplyDeletehello sir ,after creating setup it is working on my pc and if i use other pc where vs and sql server not installed and run this setup it showing Network instance error means service based database not working
ReplyDeletehi Manvendra, your sql database is not running on client machine,first install your setup file on client machine after that turn on it from below file..
Deletehttps://www.dropbox.com/s/u58q9k3ncj8w54c/problems.docx?dl=0
Is there a way to provide an option to user to just download the setup to user selected folder so that user can later install when we select 'from a website' option while publishing the code..
ReplyDeletei want solution for crystal report. whenever i run exe on another system it gives error like failed to open connection
ReplyDeleteunable to satisfy all prerequisites for WindowsFormApplication2. Setup cannot continue until all system component have been successfully installed
ReplyDeleteI have an error "Publication not possible due to a failure in generating the project" .
ReplyDeleteto activate 'Download the required components from
the location of my application 'in the Prerequisites dialog box,
you must download the file ' DotNetFX452 \ NDP452 - KB2901907 -x86 -x64- ENU.exe - Allos ' for
the item ' Microsoft .NET Framework 4.5.2 (x86 and x64) ' on the local computer
Ps: I use visual studio 2015
hello,
ReplyDeleteI have created setup file and its is created successfully.
But my query is what should i do for database backup?
and how to restore the database backup?
Please suggest me.
Thanks.
Hi, I have a desktop application with C# code in visual studio 2015 IDE connected with MS Access 2007 database. I do not want to publish in web but I want to use this application in several computer those are not connected with LAN. Is it possible?
ReplyDeletegreat job.
ReplyDeleteHi RAMASHANKER VERMA,
ReplyDeleteI was gone through your step. I was successfully run setup.
But When I run setup file and try to insert a record that time record inserted sucessfully but it can't show in datagridview in my set file. But when i in my visual studio project so there will record inserted.
That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.
ReplyDeleteBilling Software
I have created c# application with local database and i created setup file for and installed in my system and it working correctly but while installing the same setup file in another system it's not working.
ReplyDeletei am a freelancer and i have created it for my client and need to give setup file for him.
please help me on this.
Sir could you help me, i want to deploy vb.net 2010 include database access 2007 and crystal report, but when i publish the setup and i install, when i opened the aplication it cant read the database?
ReplyDeleteCan u help me to resolve it ?