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. Visual Basic
  4. how to create

how to create

Scheduled Pinned Locked Moved Visual Basic
databasecsharptutorial
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.
  • T Offline
    T Offline
    taherjaorawala
    wrote on last edited by
    #1

    how to create sql database in with userdefined name at runtime through vb.net

    C T 2 Replies Last reply
    0
    • T taherjaorawala

      how to create sql database in with userdefined name at runtime through vb.net

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

      Create a connection to the master database on the SQL Server. Create a SqlCommand that issues the CREATE DATABASE command (see SQL Books on line for details - I've no idea of your situation and I'm not going to second guess). Then you ExecuteNonQuery on the command. If the create command worked then you can now connect to your new database.


      Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos

      T 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Create a connection to the master database on the SQL Server. Create a SqlCommand that issues the CREATE DATABASE command (see SQL Books on line for details - I've no idea of your situation and I'm not going to second guess). Then you ExecuteNonQuery on the command. If the create command worked then you can now connect to your new database.


        Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos

        T Offline
        T Offline
        taherjaorawala
        wrote on last edited by
        #3

        about this I have already tried out this it woks well if the database is in sql 2000 but if the database is to be created in sql 2005 it does not allow. to solve the problem i have tried out many way but could not get it so can explain with some example. thanx for the support taher

        1 Reply Last reply
        0
        • T taherjaorawala

          how to create sql database in with userdefined name at runtime through vb.net

          T Offline
          T Offline
          theScorp
          wrote on last edited by
          #4

          Well try using "SQLDMO" dll This code worked for SQL 2000. Some code - Imports System.Data.SqlClient Imports SQLDMO 'Lists available servers Private oSqlServer As New SQLDMO.SQLServer Dim sqlDmoApplication As New SQLDMO.Application Dim serverList As SQLDMO.NameList serverList = sqlDmoApplication.ListAvailableSQLServers() 'Create Database Private Function createDB() As Boolean Dim oDatabase As SQLDMO.Database Dim oDBFileData As SQLDMO.DBFile Dim oLogFile As SQLDMO.LogFile oDatabase = New Database oDBFileData = New DBFile oLogFile = New LogFile Try 'Delete Database if it exists Call connectDB() 'If Not IsNothing(oSqlServer.Databases.Item(txtDBName.Text.Trim())) Then 'oSqlServer.Databases.Item(DBToCreate).Remove() 'Response.Write("Database with same name already exists") 'End If For i As Integer = 1 To oSqlServer.Databases.Count If txtDBName.Text.Trim().ToUpper = oSqlServer.Databases.Item(i).Name.Trim.ToUpper() Then lblAlert.Text = ("Database with same name already exists, please mention different name") Return False End If Next oDatabase.Name = txtDBName.Text.Trim() '"SOM_DB" ' Define the PRIMARY data file. oDBFileData.Name = txtDBName.Text.Trim() & "Data" ' Replace the following path with your own path to a database folder. oDBFileData.PhysicalName = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" & txtDBName.Text.Trim() & "_DB.mdf" oDBFileData.PrimaryFile = True ' Specify file growth in chunks of fixed size for all data files. oDBFileData.FileGrowthType = SQLDMO.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB oDBFileData.FileGrowth = 1 oDatabase.FileGroups.Item("PRIMARY").DBFiles.Add(oDBFileData) ' Define the database transaction log. oLogFile.Name = txtDBName.Text.Trim() & "Log1" ' Replace the following path with your own path to a database folder. oLogFile.PhysicalName = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" & txtDBName.Text.Trim() & "_DB.ldf" oDatabase.TransactionLog.LogFiles.Add(oLogFile) oSqlServer.Databases.Add(oDatabase) oDatabase = Nothing oDBFileData = Nothing oLogFile = Nothing Return True Catch ex As Exception lblAlert.Text = "Error : " & ex.Message() Return False End Try End Function "If our Mind can, the Program can !!"

          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