Exemple #1
0
        public override DataSet QueryDataSet(string query)
        {
            Debug.Assert(this.DbFlavor == DbFlavor.SqlCE);

            if (string.IsNullOrWhiteSpace(query))
            {
                return(null);
            }

            try
            {
                Connect();

                DataSet dataSet = new DataSet();

                using (DbDataAdapter da = SqlCeFactory.CreateSqlCeDataAdapter(query, this.sqlCEConnection))
                {
                    da.Fill(dataSet, "Results");
                }

                if (dataSet.Tables.Contains("Results"))
                {
                    return(dataSet);
                }
            }
            catch (Exception)
            {
                throw; // useful for setting breakpoints.
            }
            return(null);
        }
Exemple #2
0
        public override object ExecuteScalar(string cmd)
        {
            Debug.Assert(this.DbFlavor == DbFlavor.SqlCE);

            if (cmd == null || cmd.Trim().Length == 0)
            {
                return(null);
            }

            this.AppendLog(cmd);

            object result = null;

            try
            {
                Connect();
                using (DbCommand command = SqlCeFactory.CreateSqlCeCommand(cmd, this.sqlCEConnection))
                {
                    result = command.ExecuteScalar();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing SQL \"" + cmd + "\"\n" + ex.Message);
            }
            return(result);
        }
Exemple #3
0
        public override void Upgrade()
        {
            string constr = GetConnectionString(true);

            using (SqlCeEngine en = SqlCeFactory.CreateSqlCeEngine(constr))
            {
                en.Upgrade();
            }
            this.sqlCEConnection.Open();
        }
Exemple #4
0
        public override void Create()
        {
            string connectionString = GetConnectionString(true);

            if (!File.Exists(this.DatabasePath))
            {
                using (SqlCeEngine en = SqlCeFactory.CreateSqlCeEngine(connectionString))
                {
                    en.CreateDatabase();
                }
            }
        }
Exemple #5
0
        public override DbConnection Connect()
        {
            if (this.sqlCEConnection == null || this.sqlCEConnection.State != ConnectionState.Open)
            {
                if (!IsSqlCEInstalled)
                {
                    throw new MoneyException(@"<Paragraph xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>SQL Compact Edition is not installed, please download it from 
                        <Hyperlink NavigateUri='http://www.microsoft.com/download/en/details.aspx?id=17876'>Microsoft Download Center</Hyperlink> 
                        and install the version matching your operating system platform (Select <Bold>SSCERuntime_x64-ENU.exe</Bold> if you are running 
                        a 64 bit version of windows, otherwise <Bold>SSCERuntime_x86-ENU.exe</Bold>).  Then after it is installed restart the Money application.</Paragraph>");
                }

                string constr = GetConnectionString(true);
                this.sqlCEConnection = SqlCeFactory.CreateSqlCeConnection(constr);
                this.sqlCEConnection.Open();
            }
            return(this.sqlCEConnection);
        }
Exemple #6
0
        public override IDataReader ExecuteReader(string cmd)
        {
            Debug.Assert(this.DbFlavor == DbFlavor.SqlCE);

            this.AppendLog(cmd);

            try
            {
                Connect();
                using (DbCommand command = SqlCeFactory.CreateSqlCeCommand(cmd, this.sqlCEConnection))
                {
                    return(command.ExecuteReader());
                }
            }
            catch (Exception)
            {
                throw; // useful for setting breakpoints.
            }
        }
Exemple #7
0
        public override void ExecuteNonQuery(string cmd)
        {
            Debug.Assert(this.DbFlavor == DbFlavor.SqlCE);
            if (cmd == null || cmd.Trim().Length == 0)
            {
                return;
            }

            this.AppendLog(cmd);
            try
            {
                Connect();
                using (DbCommand command = SqlCeFactory.CreateSqlCeCommand(cmd, this.sqlCEConnection))
                {
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {
                throw; // useful for setting breakpoints.
            }
        }