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.Connect ionString = "Data Source=(local); DATABASE =
master;Integrat ed Security=True; user instance=true";
sqlCreateDBQuer y = " CREATE DATABASE " + DBParam.Databas eName +
" ON
PRIMARY "
+ " (NAME = " +
DBParam.DataFil eName +", "
+ " FILENAME = '" +
DBParam.DataPat hName +"', "
+ " SIZE = 5MB,"
+ " FILEGROWTH =" +
DBParam.DataFil eGrowth +") "
+ " LOG ON (NAME =" +
DBParam.LogFile Name +", "
+ " FILENAME = '" +
DBParam.LogPath Name + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH =" +
DBParam.LogFile Growth +") ";
SqlCommand myCommand = new SqlCommand(sqlC reateDBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox.Show (sqlCreateDBQue ry);
myCommand.Execu teNonQuery();
MessageBox.Show ("Database has been created successfully!",
"Create
Database", MessageBoxButto ns.OK, MessageBoxIcon. Information);
}
catch (System.Excepti on ex)
{
MessageBox.Show (ex.ToString(), "Create Database",
MessageBoxButto ns.OK, MessageBoxIcon. Information);
}
finally
{
tmpConn.Close() ;
}