469,575 Members | 1,680 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

SQL server database

EMW
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;database=SiteList")
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
Nov 20 '05 #1
4 1227
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("Create Database MyDatabase", connection)
command.ExecuteNonQuery()

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" <so*****@microsoft.com> wrote in message news:3f**********************@dreader2.news.tiscal i.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;database=SiteList")
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
Nov 20 '05 #2
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\data\saledat.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = 'Sales_log',
FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )
GO
You'll specify where the files are stored...

HTH,

Bill
"EMW" <so*****@microsoft.com> wrote in message news:3f**********************@dreader2.news.tiscal i.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;database=SiteList")
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
Nov 20 '05 #3
EMW
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:%2****************@TK2MSFTNGP09.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("Create Database MyDatabase", connection)
command.ExecuteNonQuery()

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" <so*****@microsoft.com> wrote in message news:3f**********************@dreader2.news.tiscal i.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;database=SiteList")
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
Nov 20 '05 #4
Bob
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" <so*****@microsoft.com> wrote in message
news:3f**********************@dreader2.news.tiscal i.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;database=SiteList")
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

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Nathan Sokalski | last post: by
14 posts views Thread by John Spiegel | last post: by
reply views Thread by Suresh | last post: by
2 posts views Thread by Tor Inge Rislaa | last post: by
3 posts views Thread by Lee T. Hawkins | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.