Home > Archive > MS SQL Server > November 2006 > Create SQL database with C#









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Create SQL database with C#
orenbt78

2006-11-30, 7:14 pm

Hi,

I am trying to:
1. Create a SQL database (I am working with SQL 2005 Express)
2. with a C# code
3. when the user is not the computer administrator.

I have managed to create the database file (code below). I am not sure
it is the right way.
Can you take a look please?
I would like to either create a password for these database or a
special user so only my
software will be able to control it (change data). How do I do that?


tmpConn.ConnectionString = "Data Source=(local); DATABASE =
master;Integrated Security=True; user instance=true";
sqlCreateDBQuery = " CREATE DATABASE " + DBParam.DatabaseName +
" ON
PRIMARY "
+ " (NAME = " +
DBParam.DataFileName +", "
+ " FILENAME = '" +
DBParam.DataPathName +"', "
+ " SIZE = 5MB,"
+ " FILEGROWTH =" +
DBParam.DataFileGrowth +") "
+ " LOG ON (NAME =" +
DBParam.LogFileName +", "
+ " FILENAME = '" +
DBParam.LogPathName + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH =" +
DBParam.LogFileGrowth +") ";
SqlCommand myCommand = new SqlCommand(sqlCreate
DBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox. Show(sqlCreateDBQuer
y);
myCommand.ExecuteNonQuery();
MessageBox.Show("Database has been created successfully!",
"Create
Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "Create Database",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
tmpConn.Close();
}

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com