Create a new database programatically?

Is it possible to create a new SQL Express database progamatically from VB Express? It is easy enough from the IDE, but I want to determine the schema dynamically based on user input. I have not found this discussed in Help or other articles. Can anyone point me in the right direction?

Thanks,
--Mable

[309 byte] By [Mable] at [2007-12-17]
# 1
Couldn't you just send DDL, i.e. Create Table xxxx
Column1 int NOT NULL,
...

I may not be fully understanding the issue...

BobP

BobP1339 at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
Perhaps.
What is DDL, and how do I send it?

--Mable

Mable at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

Hi,

Just make a connection to the master database of a SqlServer. This database is default to every instance of SqlServer so you don't have to worry on checking. After, connecting just execute a t-sql CREATE DATABASE commands to create a database using a SqlCommand...

cheers,

Paul June A. Domag

PaulDomag at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4
Thanks. I can connect to the master database, but as far as I can tell there is no way to use t-sql with the Express version of SQL. Am I missing something?

--Mable

Mable at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5
Hi,

First, connecto to the master database using a SqlConnection objejct. Then Execute the T-Sql with SqlCommand Object. I haven't personally tried it but I think t-sql could be used in sqlexpress...

Dim sqlCon As New SqlConnection("Password=;Persist Security Info=True;User ID=sa;Initial Catalog=master;Data Source=local")
sqlCon.Open()
Dim cmd As New SqlCommand("CREATE DATABASE dbase1", sqlCon)
cmd.ExecuteNonQuery()

Ypu can the connect to the database that you created and create your tables.
cheers,

Paul June A. Domag

PaulDomag at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6
Yes!

I could have read Help files for a month and not figured this out. Thanks for taking the time to help out a stranger.

--Mable

Mable at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...