473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to setup database in VS Setup project?

I have a .sql script that holds the configuration of a local sql express
database needed for my C# .net forms app. I would like the script to run.
Right now, I have a install_db.cmd file that basically just runs the sql
script from the command line. I made a console app that runs the
install_db.cmd

I added that console app to the application folder and then ran that as a
custom action. The command windows pops up real quick, but then goes away and
the database never actually gets created.

Any ideas how to do this better or make it actually work?
Dec 14 '07 #1
1 5001
"Brandon" <Br*****@discussions.microsoft.comwrote in message
news:17**********************************@microsof t.com...
>I have a .sql script that holds the configuration of a local sql express
database needed for my C# .net forms app. I would like the script to run.
Right now, I have a install_db.cmd file that basically just runs the sql
script from the command line. I made a console app that runs the
install_db.cmd

I added that console app to the application folder and then ran that as a
custom action. The command windows pops up real quick, but then goes away
and
the database never actually gets created.

Any ideas how to do this better or make it actually work?
You can use something like this:

using (SqlConnection connection = new
SqlConnection(connectionString))

{

using (SqlCommand command = new SqlCommand())

{

command.Connection = connection;

command.CommandText = File.ReadAllText("file.sql");

connection.Open();

command.ExecuteNonQuery();

}

}

The difference is that you need to execute one batch at a time. You can't
execute the whole thing at once. I have used a regular expression and the
..Split method to split the file on the "GO" commands, then execute each
batch one at a time.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Dec 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: santhosh_176 | last post by:
:I Created a Pocket PC application for iPAQ 5450. Every thing went fine even installer creation. I could run the setup and install it into the actual device and worked fine. The application enables...
3
by: Sunny | last post by:
Hi I have a Database Application that i am trying to create a SETUP for. The application uses three custom Ms access Databases. Those database i added in the correct folder in the SETUP Project of...
0
by: Sunny | last post by:
Hi I have made a Database Application for which i am trying to create a SETUP Project. The application uses three custom Ms access Databases. Those database i added in the correct folder in the...
0
by: Oz | last post by:
Hi We in our company build asp.net and MS SQL Server apps for deployment on clients' machines. We have created an Installer class (DBInstaller) which runs several scripts to build a database,...
3
by: John | last post by:
Hi I have an app to deal with two companies A & B within a group of companies depending on which database is selected. Is it possible for setup to ask the user at install time which company they...
4
by: Saber | last post by:
In VS 2005 I made a setup project for my application. The application uses a mdb file and needs Microsoft Jet OLE DB Provider to run on another PCs. In Prerequisites section of Setup Property...
4
by: Paul | last post by:
Hi, I am developing a c# windows .NET application. The application is going to run on a standalone PC and use an access database. I have figured out that I will need to create a project and add it...
3
by: Maha | last post by:
Hi all, It is my first time with windows forms applications using Visual Studio .net 2005, and I have a question; My project is a database driven one which will be distributed on a CD. I...
2
kaushalparik
by: kaushalparik | last post by:
hi all, i am working with Desktop application, and trying to create a setup project. i finalized my application and now creating the setup for that application. what i need to do is, with in...
0
by: winbala | last post by:
I am currently working in VB.NET project which is a desktop application with Access as database. I had made a setup project of my application. I ran the same in another machine which had Win 2000...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.