How to execute sql file in windows service

Posted on 2011-05-04
Last Modified: 2012-05-11
How to execute SQL file in wSindows service
Question by:ankouny
    LVL 31

    Expert Comment

    LVL 16

    Accepted Solution

    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)); 

    Open in new window


    Author Comment

    Can you lease put it in ?

    Author Comment

    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.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now