• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

How to execute sql file in windows service

How to execute SQL file in VB.net wSindows service
  • 2
1 Solution
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
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

ankounyAuthor Commented:
Can you lease put it in VB.net ?
ankounyAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now