SQL server database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EMW

    #1

    SQL server database

    How can I create a SQL server database in my VB.NET program?
    I've MSSQLServer installed and running.

    If a database is created, where is it stored?

    I used the following code, didn't get any errors, but cannot find a new file:

    Dim con As SqlConnection = New SqlConnection(" server=(local); Integrated Security=SSPI;d atabase=SiteLis t")
    Dim cmdLijst As SqlDataAdapter = New SqlDataAdapter( "CREATE DATABASE ", con)
    'here some code to create the table?
    'here some code to put the info from a dataset into the sql database?
    con.close

    Is with this code the database created?

    thanks
    Eric
  • Martin Robins

    #2
    Re: SQL server database

    No.

    My VB is rusty but off the cuff ...

    Dim connnection as New SqlConnection(" server=(local); Integrated Security=SSPI"; database=master )
    Dim command as New SqlCommand("Cre ate Database MyDatabase", connection)
    command.Execute NonQuery()

    Then simply add the necessary commands to create your tables etc. It is probably a lot easier though to create the database from VS or Enterprise manager and then simply use it.

    "EMW" <someone@micros oft.com> wrote in message news:3fbe821d$0 $36110$5fc3050@ dreader2.news.t iscali.nl...
    How can I create a SQL server database in my VB.NET program?
    I've MSSQLServer installed and running.

    If a database is created, where is it stored?

    I used the following code, didn't get any errors, but cannot find a new file:

    Dim con As SqlConnection = New SqlConnection(" server=(local); Integrated Security=SSPI;d atabase=SiteLis t")
    Dim cmdLijst As SqlDataAdapter = New SqlDataAdapter( "CREATE DATABASE ", con)
    'here some code to create the table?
    'here some code to put the info from a dataset into the sql database?
    con.close

    Is with this code the database created?

    thanks
    Eric

    Comment

    • William Ryan

      #3
      Re: SQL server database

      Check out BOL, but assuming you have the permissions, you'll just set the command text like:

      USE master
      GO
      CREATE DATABASE Sales
      ON
      ( NAME = Sales_dat,
      FILENAME = 'c:\program files\microsoft sql server\mssql\da ta\saledat.mdf' ,
      SIZE = 10,
      MAXSIZE = 50,
      FILEGROWTH = 5 )
      LOG ON
      ( NAME = 'Sales_log',
      FILENAME = 'c:\program files\microsoft sql server\mssql\da ta\salelog.ldf' ,
      SIZE = 5MB,
      MAXSIZE = 25MB,
      FILEGROWTH = 5MB )
      GO


      You'll specify where the files are stored...

      HTH,

      Bill
      "EMW" <someone@micros oft.com> wrote in message news:3fbe821d$0 $36110$5fc3050@ dreader2.news.t iscali.nl...
      How can I create a SQL server database in my VB.NET program?
      I've MSSQLServer installed and running.

      If a database is created, where is it stored?

      I used the following code, didn't get any errors, but cannot find a new file:

      Dim con As SqlConnection = New SqlConnection(" server=(local); Integrated Security=SSPI;d atabase=SiteLis t")
      Dim cmdLijst As SqlDataAdapter = New SqlDataAdapter( "CREATE DATABASE ", con)
      'here some code to create the table?
      'here some code to put the info from a dataset into the sql database?
      con.close

      Is with this code the database created?

      thanks
      Eric

      Comment

      • EMW

        #4
        Re: SQL server database

        Thanks, Martin.

        The reason I need to do it programmaticly is because it is an conversion program, so after each conversion it creates a SQL database

        rg,
        Eric
        "Martin Robins" <martin - robins @ ntlworld dot com> schreef in bericht news:%23hbyAkHs DHA.2364@TK2MSF TNGP09.phx.gbl. ..
        No.

        My VB is rusty but off the cuff ...

        Dim connnection as New SqlConnection(" server=(local); Integrated Security=SSPI"; database=master )
        Dim command as New SqlCommand("Cre ate Database MyDatabase", connection)
        command.Execute NonQuery()

        Then simply add the necessary commands to create your tables etc. It is probably a lot easier though to create the database from VS or Enterprise manager and then simply use it.

        "EMW" <someone@micros oft.com> wrote in message news:3fbe821d$0 $36110$5fc3050@ dreader2.news.t iscali.nl...
        How can I create a SQL server database in my VB.NET program?
        I've MSSQLServer installed and running.

        If a database is created, where is it stored?

        I used the following code, didn't get any errors, but cannot find a new file:

        Dim con As SqlConnection = New SqlConnection(" server=(local); Integrated Security=SSPI;d atabase=SiteLis t")
        Dim cmdLijst As SqlDataAdapter = New SqlDataAdapter( "CREATE DATABASE ", con)
        'here some code to create the table?
        'here some code to put the info from a dataset into the sql database?
        con.close

        Is with this code the database created?

        thanks
        Eric

        Comment

        • Bob

          #5
          Re: SQL server database

          Bring up Enterprise Manager, right-click on an existing database, and select All
          Tasks/Generate SQL Script. Go to the Options tab and in the Secutiry Scipting
          Options section, check "Script database". Go back to the General tab and click
          on the Preview button - you will get a complete script on how a database is
          created with all its options using T-SQL. This can be placed directly in code,
          or entirely in a stored procedure if you are comfortable with working with
          dynamic sql.

          Bob

          "EMW" <someone@micros oft.com> wrote in message
          news:3fbe821d$0 $36110$5fc3050@ dreader2.news.t iscali.nl...
          How can I create a SQL server database in my VB.NET program?
          I've MSSQLServer installed and running.

          If a database is created, where is it stored?

          I used the following code, didn't get any errors, but cannot find a new file:

          Dim con As SqlConnection = New SqlConnection(" server=(local); Integrated
          Security=SSPI;d atabase=SiteLis t")
          Dim cmdLijst As SqlDataAdapter = New SqlDataAdapter( "CREATE DATABASE ", con)
          'here some code to create the table?
          'here some code to put the info from a dataset into the sql database?
          con.close

          Is with this code the database created?

          thanks
          Eric

          Comment

          Working...