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. Database & SysAdmin
  3. Database
  4. create database, which parameter

create database, which parameter

Scheduled Pinned Locked Moved Database
databasemysqlcom
7 Posts 2 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.
  • L Offline
    L Offline
    luccingolo
    wrote on last edited by
    #1

    Hi all I'm experiencing troubles with the code from this site. Which parameter is exspected instead of:"master..sysdatabases" in the following sql-command:Dim mySQL As String = _ "IF EXISTS (" & _ "SELECT * " & _ "FROM master..sysdatabases " & _ "WHERE Name = 'MyDatabase')" & vbCrLf & _ "DROP DATABASE MyDatabase " & vbCrLf & _ "CREATE DATABASE MyDatabase " Thanks, Lucchingolo

    C 1 Reply Last reply
    0
    • L luccingolo

      Hi all I'm experiencing troubles with the code from this site. Which parameter is exspected instead of:"master..sysdatabases" in the following sql-command:Dim mySQL As String = _ "IF EXISTS (" & _ "SELECT * " & _ "FROM master..sysdatabases " & _ "WHERE Name = 'MyDatabase')" & vbCrLf & _ "DROP DATABASE MyDatabase " & vbCrLf & _ "CREATE DATABASE MyDatabase " Thanks, Lucchingolo

      C Offline
      C Offline
      Corporal Agarn
      wrote on last edited by
      #2

      What database engine are you using?

      L 1 Reply Last reply
      0
      • C Corporal Agarn

        What database engine are you using?

        L Offline
        L Offline
        luccingolo
        wrote on last edited by
        #3

        I'm using Microsoft SQL Server 2008

        C 1 Reply Last reply
        0
        • L luccingolo

          I'm using Microsoft SQL Server 2008

          C Offline
          C Offline
          Corporal Agarn
          wrote on last edited by
          #4

          Okay, by right clicking on a database in SSMS you can select "Script Database as" then select "DROP to" you can then find that you are looking for sys.databases As this looks like .NET code you may not have access to SSMS so here is an T-SQL example:

          IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDatabase')
          DROP DATABASE [MyDatabase]

          L 1 Reply Last reply
          0
          • C Corporal Agarn

            Okay, by right clicking on a database in SSMS you can select "Script Database as" then select "DROP to" you can then find that you are looking for sys.databases As this looks like .NET code you may not have access to SSMS so here is an T-SQL example:

            IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDatabase')
            DROP DATABASE [MyDatabase]

            L Offline
            L Offline
            luccingolo
            wrote on last edited by
            #5

            Sorry, still get an error. Maybe i misundertood you. Fact is that i still get an error. What i did is using your sql-command as string for my SQL-command. What I mean is this: In the Form1_Load-Event of my Application(project). MyConnection = "Server=localhost;" & "DataBase=;" & "Integrated Security=SSPI" 'Your line of code Dim mySQL As String = "IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDatabase')DROP DATABASE [MyDatabase]" Try Dim conn As New SqlConnection(MyConnection) Dim myCmd As New SqlCommand(mySQL, conn) conn.Open() myCmd.ExecuteNonQuery() conn.Close() . . . Last but not least, don't forget that the point is not only to "drop" a Database but i'm trying so hard to create a SQL-Database. :) thank you, Lucchingolo

            C 1 Reply Last reply
            0
            • L luccingolo

              Sorry, still get an error. Maybe i misundertood you. Fact is that i still get an error. What i did is using your sql-command as string for my SQL-command. What I mean is this: In the Form1_Load-Event of my Application(project). MyConnection = "Server=localhost;" & "DataBase=;" & "Integrated Security=SSPI" 'Your line of code Dim mySQL As String = "IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDatabase')DROP DATABASE [MyDatabase]" Try Dim conn As New SqlConnection(MyConnection) Dim myCmd As New SqlCommand(mySQL, conn) conn.Open() myCmd.ExecuteNonQuery() conn.Close() . . . Last but not least, don't forget that the point is not only to "drop" a Database but i'm trying so hard to create a SQL-Database. :) thank you, Lucchingolo

              C Offline
              C Offline
              Corporal Agarn
              wrote on last edited by
              #6

              You will need a semicolon before the drop. If you are not dropping a database I would suggest not even coding the if - drop. I have not programmed this at the .NET end. You may need to go to the VS forum.

              L 1 Reply Last reply
              0
              • C Corporal Agarn

                You will need a semicolon before the drop. If you are not dropping a database I would suggest not even coding the if - drop. I have not programmed this at the .NET end. You may need to go to the VS forum.

                L Offline
                L Offline
                luccingolo
                wrote on last edited by
                #7

                Thank your, I will give it a try in the Visual Basic forum. I could not find a VS-forum. Guess you meant the VB-forum.

                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