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

  • Home
  • SEARCH
  • 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 6786283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:13:37+00:00 2026-05-26T17:13:37+00:00

I am maintaining a simple DB tool that executes CreateDatabase on our EF model,

  • 0

I am maintaining a simple DB tool that executes CreateDatabase on our EF model, and uses SMO to run some .sql scripts.

It currently uses:

var svrConnection = new ServerConnection(sqlConnection);
var server = new Server(svrConnection);
server.ConnectionContext.ExecuteNonQuery(fullSqlScript);

Is there a way to execute a TSQL script in .Net without using SMO?

Or, is there a way to successfully use SMO in an application without installing the thing on the server I’m running it on?

Any alternative that will be useful to me will require no installation on the box, besides xcopy of assemblies for my tool. It also must guarantee that the script will operate in exactly the same way without additional testing/verification.

The scripts use GO, etc, and cannot/should not be broken up – they’re generated by third-party tools (aspnet_regsql.exe), and by hand (but are stale at this point), so I do not want to touch them if I can avoid it.

I’m pretty sure the suggestions in the comments on this answer are wrong, because I’m pretty sure GO isn’t directly replacable with ;. If I’m wrong, please let me know 🙂

I’m trying to work around this problem:

Could not load file or assembly ‘Microsoft.SqlServer.SqlClrProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91’ or one of its dependencies. The system cannot find the file specified.

The fix mentioned here was to install SMO, which requires other packages, which isn’t ideal for me.


Final solution, based off Russell McClure’s answer:

In the end I am going to end up with sqlcmd.exe, since scripts written for it (anything with GO in it) could do way too much to replicate through SqlCommand.ExecuteNonQuery in my own code. And since it has the same level of dependencies as SMO, and would take some work to wrap in a programatically clean way, I’m just going to stick with SMO.

All the libraries and tools I mentioned are part of :

http://www.microsoft.com/download/en/details.aspx?id=16978

  • 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-26T17:13:37+00:00Added an answer on May 26, 2026 at 5:13 pm

    Run your T-SQL through sqlcmd.exe.

    Or, what I normally do is actually read the file contents (my sql files are normally embedded resources) and then pass it to this function to split it into batches acceptable to ADO.NET:

    public static string[] ParseSqlStatementBatch(string sqlStatementBatch)
    {
       // split the sql into seperate batches by dividing on the GO statement
       Regex sqlStatementBatchSplitter = new Regex(@"^\s*GO\s*\r?$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
       return sqlStatementBatchSplitter.Split(sqlStatementBatch);
    }
    

    Here is an example usage:

    string[] sqlStatements = DataAccess.DatabaseWrapper.ParseSqlStatementBatch(FileContents);
    
    using (SqlConnection sqlConnection = new SqlConnection(connectionString))
    {
       sqlConnection.Open();
       using (SqlCommand command = sqlConnection.CreateCommand())
       {
          command.CommandType = CommandType.Text;
          command.CommandTimeout = Registry.RegistryWrapper.GetSqlCommandTimeout();
          foreach (string sqlStatement in sqlStatements)
          {
             if (sqlStatement.Length > 0)
             {
                command.CommandText = sqlStatement;
                command.ExecuteNonQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm maintaining some code that uses a *= operator in a query to a
I am developing / maintaining a tool that allows users to run queries against
I have a web-site that generates some simple tabular data as html tables, many
I have an ASP.NET site that I am maintaining. Currently it has code that
I am maintaining some code that has a trigger on a table to increment
I am maintaining a simple php-based in-house cms. I'd like to search the text
I am maintaining an app for a client that is used in two locations.
I have a project where lots of the objects hold state by maintaining simple
I'm trying to put together a very simple REST-style interface for communicating with our
I have a web-app consisting of some html forms for maintaining some tables (SQlite,

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.