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 6772659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:34:30+00:00 2026-05-26T15:34:30+00:00

Before I write this myself, is there a c# method out there floating around

  • 0

Before I write this myself, is there a c# method out there floating around that will create the tables, sprocs, and views that get installed by aspnetregsql?

  • 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-26T15:34:30+00:00Added an answer on May 26, 2026 at 3:34 pm

    As far as I know there is no API to do this directly – the aspnet_regsql.exe tool just references script files on disk anyhow.

    For a head start on how to implement this yourself:

    You can manually execute aspnet_regsql.exe via Process.Start.

    Or you can run the program from the command line, with command line options to dump out the script. Then edit those scripts to be DB agnostic (or don’t – up to you), store those scripts as embedded resources in your application, extract them at runtime, and use a SqlConnection and ExecuteNonQuery to run those scripts against a database.

    Here are the command line options for aspnet_regsql.exe:

    http://msdn.microsoft.com/en-us/library/ms229862(v=vs.80).aspx

    Here’s some code I have used to implement the second option:

    ExecuteSqlScriptResource("MyDb", "MyAssemblyName.Scripts.aspnet_regsql_add.sql");
    
    // ...
    
    static void ExecuteSqlScriptResource(string connectionName, string resourcePath)
    {
        using (Stream scriptStream = Assembly.GetExecutingAssembly()
            .GetManifestResourceStream(resourcePath)
            )
        {
            if (scriptStream == null)
            {
                WriteLine(string.Format("Failed to open resource {0}", resourcePath));
                return;
            }
    
            using (
                var sqlConnection = new SqlConnection(
                    ConfigurationManager
                        .ConnectionStrings[connectionName].ConnectionString
                    )
                )
            {
                using (var streamReader = new StreamReader(scriptStream))
                {
                    var svrConnection = new ServerConnection(sqlConnection);
                    var server = new Server(svrConnection);
                    server.ConnectionContext.ExecuteNonQuery(streamReader.ReadToEnd());
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sure I could write this myself, but before I go reinventing the wheel is
Before I write my own I will ask all y'all. I'm looking for a
Is there a SQL or PHP script that I can run that will change
is there an easy way to timeout an SQL statement so that it will
before this I wrote all jquery-code into main fail. Now I want to move
I noticed people wrote about this circular reference problem quite a bit before but
If you read this thread before - forget everything I wrote , I must
I'm trying to write to a plist file using writeToFile, before I write I
How many people actually write an SDD document before writing a single line of
I write LaTeX docs in French, and babel package puts extra spaces before colons

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.