Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Run SQL Server script from C# code

Run SQL Server script from C# code

Scheduled Pinned Locked Moved C#
csharpdatabasesql-serversysadmintools
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sushant Duggal
    wrote on last edited by
    #1

    Hi friends, I want to run sql server 2000 script (abc.sql) file from my C# application. Can you guide me?? Regards,

    Sushant Duggal.

    B P C S 4 Replies Last reply
    0
    • S Sushant Duggal

      Hi friends, I want to run sql server 2000 script (abc.sql) file from my C# application. Can you guide me?? Regards,

      Sushant Duggal.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      read it as textfile than paste content of it in SqlDataAdapter or SqlCommand or in SqlDataSource


      I Love SQL

      1 Reply Last reply
      0
      • S Sushant Duggal

        Hi friends, I want to run sql server 2000 script (abc.sql) file from my C# application. Can you guide me?? Regards,

        Sushant Duggal.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        I would suggest that you look at using Process.Start to run osql.exe.

        the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
        Deja View - the feeling that you've seen this post before.

        S 1 Reply Last reply
        0
        • S Sushant Duggal

          Hi friends, I want to run sql server 2000 script (abc.sql) file from my C# application. Can you guide me?? Regards,

          Sushant Duggal.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Sushant Duggal wrote:

          Can you guide me??

          You can run just about any SQL through a SqlCommand. Just read the file in to a string and dump the string into the SqlCommand. NOTE: GO is not SQL. It is a preprocessor command to Query Analyzer to tell it to split the file into batches. If your file has GOs in it, you need to split it up and send them as separate SqlCommands.


          Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

          1 Reply Last reply
          0
          • P Pete OHanlon

            I would suggest that you look at using Process.Start to run osql.exe.

            the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
            Deja View - the feeling that you've seen this post before.

            S Offline
            S Offline
            Sushant Duggal
            wrote on last edited by
            #5

            Hi Pete, Thanks for your post. Can you tell me after starting the osql process, what I need to do. Regards,

            Sushant Duggal.

            1 Reply Last reply
            0
            • S Sushant Duggal

              Hi friends, I want to run sql server 2000 script (abc.sql) file from my C# application. Can you guide me?? Regards,

              Sushant Duggal.

              S Offline
              S Offline
              Sushant Duggal
              wrote on last edited by
              #6

              Thanks for the reply friends. Regards,

              Sushant Duggal.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups