I'm completely new to database programming. I'm working with Visual Studio 2010 and want to create a database programmatically.
So far I've tried to connect to a SQL Server Compact Edition like this:
public class HistoryDBAccess
{
private SqlConnection conn = new SqlConnection();
public HistoryDBAccess()
{
conn.ConnectionString = @"Server=localhost;Integrated security=SSPI;database=master";
string str = "CREATE DATABASE MyDatabase ON PRIMARY " +
"(NAME = MyDatabase_Data, " +
"FILENAME = 'C:\\MyDatabaseData.mdf', " +
"SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = MyDatabase_Log, " +
"FILENAME = 'C:\\MyDatabaseLog.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
SqlCommand myCommand = new SqlCommand(str, conn);
try
{
conn.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
if (conn.State == System.Data.ConnectionState.Open)
{
conn.Close();
}
}
}
}
The connection in the Ctor fails with the message that a connection could not be established.
Using the database wizard with VS2010 is fine, but how I can see the SQLCe server under windows 7?
Is it somewhere under the control panel and do I need a default password in the connection string?
Many thanks,
Juergen