By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

how to create database in mssql server

P: n/a
hi,
how to create database in mssql server using c#. We can
create msacess database using adox, similiarly how to
create sql server database using c#.

Regards,
Nanda.
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
hi,
thanks for your reply. I need to create database in sql
server at runtime. So i like to create the database using
c#.
Nov 15 '05 #2

P: n/a
Kun
How about create all your SQL statement in setupdb.sql and then as from your
code just pass the file to sqlserver. I used it from Msdos prompt sometime.

I think he might want to provide a function like setup new database for his
application :D

"NULL" <Thomas-dot-Delrue-at-Tiscali-dot-Be> wrote in message
news:2m********************************@4ax.com...
On Tue, 2 Sep 2003 02:37:17 -0700, "Nanda" <cs******@hotmail.com>
wrote:
hi,
how to create database in mssql server using c#. We can
create msacess database using adox, similiarly how to
create sql server database using c#.


-Connect to the SQL Server with appropriate user account (one that CAN
create dbases)
-start your CREATE DATABASE statement (See 'books online')
-execute a USE myDataBaseName statement to switch to that DB
-populate the DB with tables, SPs, views, etc...

Why would you want to create a DB from C#, why not use the Enterprise
Mgr or Query Analyzer (using a SQL Script)???

--
NULL

Nov 15 '05 #3

P: n/a
On Tue, 2 Sep 2003 02:57:59 -0700, "Nanda" <cs******@hotmail.com>
wrote:
hi,
thanks for your reply. I need to create database in sql
server at runtime. So i like to create the database using
c#.


You are creating a SQL Server mgmt app in C#??? :|

--
NULL

Nov 15 '05 #4

P: n/a
hi all,
thanks for your inputs. I dont create SQL Server mgmt
app in C#. I just need to create a database at runtime.
I used ExecuteNonQuery method to create the database.

Regards,
Nanda.
-----Original Message-----
Hi Nanda,
You will have to use the ExecuteNonQuery method.

Eg:
String sql = "CREATE DATABASE mydb ON PRIMARY (Name=test_data, filename ='C:\\mysql\\mydb_data.mdf', size=3,maxsize=5, filegrowth=10%) log on(name=mydbb_log,
filename='C:\\mysql\\mydb_log.ldf',size=3,maxsize =20,fileg rowth=1)"....
....
cmd.ExecuteNonQuery();

Check out this article for more info...

http://www.c- sharpcorner.com/Code/2002/Mar/CreatingDBProgrammaticallyMCB
..asp

Cheers
Benny
Nanda wrote:
hi,
how to create database in mssql server using c#. We can create msacess database using adox, similiarly how to
create sql server database using c#.

Regards,
Nanda.


.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.