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
  1. Home
  2. General Programming
  3. C#
  4. How to Create DB in SQL server

How to Create DB in SQL server

Scheduled Pinned Locked Moved C#
databasesql-serversysadmintoolshelp
4 Posts 3 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.
  • J Offline
    J Offline
    Joe Rozario
    wrote on last edited by
    #1

    Dear friends, i have some problems like i need to create application , that "creates Database,Table,Views" and need to insert default values. at first i have created script file which contains all the operation, then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed. is it possible to create the DB,Tables, View in any other way ?? Thank you

    D G 2 Replies Last reply
    0
    • J Joe Rozario

      Dear friends, i have some problems like i need to create application , that "creates Database,Table,Views" and need to insert default values. at first i have created script file which contains all the operation, then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed. is it possible to create the DB,Tables, View in any other way ?? Thank you

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      You can keep your scripts in .sql files and then execute them using ADO.Net through the code.

      J 1 Reply Last reply
      0
      • D dan sh

        You can keep your scripts in .sql files and then execute them using ADO.Net through the code.

        J Offline
        J Offline
        Joe Rozario
        wrote on last edited by
        #3

        Thanks....for reply i got info form [^]

        1 Reply Last reply
        0
        • J Joe Rozario

          Dear friends, i have some problems like i need to create application , that "creates Database,Table,Views" and need to insert default values. at first i have created script file which contains all the operation, then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed. is it possible to create the DB,Tables, View in any other way ?? Thank you

          G Offline
          G Offline
          Gonzalo Cao
          wrote on last edited by
          #4

          Hi!! You can execute them using the .NET Sql or OleDB connector. Something like this will work System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection([ConnectionString]); cnn.Open(); using (System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand([query], cnn)) { Command.ExecuteNonQuery(); Command.Dispose(); cnn.Close(); cnn.Dispose(); } Obviously if you are going to execute a bunch of query because you're going to create all the tables, insert all the defaults and such in the same process you should use transactions. Information about how to do that can be found in the MSDN, you only need to add a couple of lines more. Hope this helps :)

          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