|
Posted by orenbt78 on 11/30/06 16:15
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(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox.Show(sqlCreateDBQuery);
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();
}
Navigation:
[Reply to this message]
|