[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to execute sql file in windows service

Posted on 2011-05-04
4
Medium Priority
?
287 Views
Last Modified: 2012-05-11
How to execute SQL file in VB.net wSindows service
0
Comment
Question by:ankouny
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 1000 total points
ID: 35689713
If Script files are properly designed then you can use following
 
void Execuate(string fileName )

        {

            string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True";

            FileInfo file = new FileInfofileName ); 

            string script = file.OpenText().ReadToEnd(); 

            SqlConnection conn = new SqlConnection(sqlConnectionString); 

            Server server = new Server(new ServerConnection(conn)); 

            server.ConnectionContext.ExecuteNonQuery(script);

        }

Open in new window

0
 

Author Comment

by:ankouny
ID: 35689817
Can you lease put it in VB.net ?
0
 

Author Comment

by:ankouny
ID: 35689922
Please notice that I need to run the sql file in a windows service.
I tried to use the OSQL process but it is not working.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question