0

I have a section of code dedicated to creating several tables, yet it creates the first one then throws exceptions, but the exception contains nothing, its blank. Here is my code:

string connectionString = "DataSource=\"EventControl.sdf\"";
        SqlCeEngine en = new SqlCeEngine(connectionString);
        en.CreateDatabase();
        string createTable = "CREATE TABLE Login (userName nvarchar(50), UserType nvarchar(10), Salt nvarchar(100), Hash nvarchar(100))";
        string connection = "Data Source =\"EventControl.sdf\"";
        SqlCeConnection connexion = new SqlCeConnection(connection);
        SqlCeCommand table = new SqlCeCommand(createTable, connexion);
        try
        {
            connexion.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        table.ExecuteNonQuery();
        connexion.Close();
        string createTable1 = "CREATE TABLE Logs (LogNo nvarchar(5), LoggedBy nvarchar(20), DateAndTime nvarchar(20), Callsign nvarchar(20), Category nvarchar(20), SubCategory nvarchar(20), Escalated nvarchar(15), Summary nvarchar(MAX), Complete nvarchar(10))";
        string connection1 = "Data Source =\"EventControl.sdf\"";
        SqlCeConnection connexion1 = new SqlCeConnection(connection1);
        SqlCeCommand table1 = new SqlCeCommand(createTable1, connexion1);
        try
        {
            connexion1.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        table1.ExecuteNonQuery();
        connexion1.Close();
        string createTable2 = "CREATE TABLE Sites (SiteName nvarchar(100),SiteAddress nvarchar(100),PersonInCharge nvarchar(100))";
        string connection2 = "Data Source =\"EventControl.sdf\"";
        SqlCeConnection connexion2 = new SqlCeConnection(connection2);
        SqlCeCommand table2 = new SqlCeCommand(createTable2, connexion2);
        try
        {
            connexion2.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        table2.ExecuteNonQuery();
        connexion2.Close();
        string createTable3 = "CREATE TABLE Categories (Category nvarchar(50), SubCategory nvarchar(50))";
        string connection3 = "Data Source =\"EventControl.sdf\"";
        SqlCeConnection connexion3 = new SqlCeConnection(connection3);
        SqlCeCommand table3 = new SqlCeCommand(createTable3, connexion3);
        try
        {
            connexion3.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        table3.ExecuteNonQuery();
        connexion3.Close();
        string createTable4 = "CREATE TABLE Callsigns (StaffName nvarchar (50), Callsign nvarchar(50))";
        string connection4 = "Data Source =\"EventControl.sdf\"";
        SqlCeConnection connexion4 = new SqlCeConnection(connection4);
        SqlCeCommand table4 = new SqlCeCommand(createTable4, connexion4);
        try
        {
            connexion4.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        table4.ExecuteNonQuery();
        connexion4.Close();
        string createTable5 = "CREATE TABLE Events (EventName nvarchar(100), EventLocation nvarchar(100), PersonInCharge nvarchar(100))";
        string connection5 = "Data Source =\"EventControl.sdf\"";
        SqlCeConnection connexion5 = new SqlCeConnection(connection5);
        SqlCeCommand table5 = new SqlCeCommand(createTable5, connexion5);
        try
        {
            connexion5.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        table5.ExecuteNonQuery();
        connexion5.Close();

It gets to table1.ExecuteNonQuery then stops. Can anyone help??

PS And before anyone says why not just create the databases in VS, its because i have tried that, and they worked fine on my computer but when i created the setup files for deployment the folders got all messed up and the program wouldnt recognise the DB anymore

4

3 回答 3

1

将表 1 中的 MAX 值更改为 4000

于 2013-10-09T05:12:04.137 回答
1

SQl Server Compact 不支持数据类型 nvarchar(MAX),请改用 ntext:

Summary ntext,
于 2013-10-09T07:04:18.147 回答
-1
SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");
engine.Compact(null);
//you need add a user and a password to acess the database 
engine.Compact("Data Source=; Password =a@3!7f$dQ;");

http://msdn.microsoft.com/pt-br/library/system.data.sqlserverce.sqlceengine.compact(v=vs.100).aspx http://msdn.microsoft.com/en-us/library/ tk883fc7(v=vs.100).aspx

于 2013-10-09T04:43:34.823 回答