how to create
-
how to create sql database in with userdefined name at runtime through vb.net
-
how to create sql database in with userdefined name at runtime through vb.net
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 youExecuteNonQuery
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
-
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 youExecuteNonQuery
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
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
-
how to create sql database in with userdefined name at runtime through vb.net
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 !!"