Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3795798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:08:19+00:00 2026-05-19T13:08:19+00:00

I have many files for procedures, views, functions, etc. I want to execute these

  • 0

I have many files for procedures, views, functions, etc.

I want to execute these files (creating components) in appropriate database on SQL Server 2005/2008.

Also the point is I want to execute them using C#.

Another point to mention, I want the application to be such that I can execute this files on a remote SQL Server too. Also client machine may not have osql,sqlcmd command tool.

Can someone please guide me on this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:08:20+00:00Added an answer on May 19, 2026 at 1:08 pm

    This depends on what sort of files they are. If, for example, they only contain actual T-SQL commands (and aren’t batch files that you’d run in, say, SSMS, which would contain a batch separator like GO), then you just need to create a connection, a command, then read the contents of the file and use that to populate the CommandText property of the command.

    For example:

    void ExecuteFile(string connectionString, string fileName)
    {
        using(SqlConnection conn = new SqlConnection(connectionString))
        {
            string data = System.IO.File.ReadAllText(fileName);
    
            conn.Open();
    
            using(SqlCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = data;
                cmd.ExecuteNonQuery();
            }
        }
    }
    

    If it’s a batch file, you’ll need to split the file into individual batches and process those individually. The simplest method is just to use string.Split, but bear in mind that it won’t respect SQL parsing rules when it splits (for example, if GO appears within a SQL statement, it’s going to split the command up into two batches, which will obviously fail).

    More generally, you can see what you’d need to do here by modifying the code in this way:

    string[] batches = SplitBatches(System.IO.File.ReadAllText(fileName));
    
    conn.Open();
    
    using(SqlCommand cmd = conn.CreateCommand())
    {
        foreach(string batch in batches)
        {
            cmd.CommandText = batch;
            cmd.ExecuteNonQuery();
        }
    }
    

    The implementation of a function called SplitBatches is up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 views in SQL set up: PurchaseOrder PurchaseOrderLineItems These have many columns
I have many many files in a folder, and I want to process them
I have many directories with files in them. I want to create a comma
I have many (>600) EPS files(300 KB - 1 MB) in database. In my
I have many stored procedures and functions in a folder. I have a batch
I am working in linux bash environment, and I have many files to edit,
I have many text files containing bank transactions in the middle of them. Each
I have many js files, with some naming convention. If there any tool that
I have many text files, their total size is about 300GB ~ 400GB. They
I have files which have many empty cells which appear as NaNs when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.