当前位置: 首页>>代码示例>>C#>>正文


C# SqlCeEngine类代码示例

本文整理汇总了C#中SqlCeEngine的典型用法代码示例。如果您正苦于以下问题:C# SqlCeEngine类的具体用法?C# SqlCeEngine怎么用?C# SqlCeEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SqlCeEngine类属于命名空间,在下文中一共展示了SqlCeEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        public virtual void Initialize()
        {
            TestHelper.SetupLog4NetForTests();
            TestHelper.InitializeContentDirectories();

            Path = TestHelper.CurrentAssemblyDirectory;
            AppDomain.CurrentDomain.SetData("DataDirectory", Path);

            Resolution.Freeze();

            //Delete database file before continueing
            string filePath = string.Concat(Path, "\\UmbracoPetaPocoTests.sdf");
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            //Get the connectionstring settings from config
            var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName];

            //Create the Sql CE database
            var engine = new SqlCeEngine(settings.ConnectionString);
            engine.CreateDatabase();

            SqlSyntaxContext.SqlSyntaxProvider = SqlCeSyntax.Provider;
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:26,代码来源:ValidateOlderSchemaTest.cs

示例2: MultiRSSqlCE

        public void MultiRSSqlCE()
        {
            if (File.Exists("Test.sdf"))
                File.Delete("Test.sdf");

            var cnnStr = "Data Source = Test.sdf;";
            var engine = new SqlCeEngine(cnnStr);
            engine.CreateDatabase();

            using (var cnn = new SqlCeConnection(cnnStr))
            {
                cnn.Open();

                cnn.Execute("create table Posts (ID int, Title nvarchar(50), Body nvarchar(50), AuthorID int)");
                cnn.Execute("create table Authors (ID int, Name nvarchar(50))");

                cnn.Execute("insert Posts values (1,'title','body',1)");
                cnn.Execute("insert Posts values(2,'title2','body2',null)");
                cnn.Execute("insert Authors values(1,'sam')");

                var data = cnn.Query<PostCE, AuthorCE, PostCE>(@"select * from Posts p left join Authors a on a.ID = p.AuthorID", (post, author) => { post.Author = author; return post; }).ToList();
                var firstPost = data.First();
                firstPost.Title.IsEqualTo("title");
                firstPost.Author.Name.IsEqualTo("sam");
                data[1].Author.IsNull();
                cnn.Close();
            }
        }
开发者ID:jdomzhang,项目名称:dapper-dot-net,代码行数:28,代码来源:Tests.cs

示例3: CreateDB

        /// <summary>
        /// Create the initial database
        /// </summary>
        private void CreateDB()
        {
            var connection = new SqlCeConnection(this.path);

            try
            {
                var eng = new SqlCeEngine(this.path);
                var cleanup = new System.Threading.Tasks.Task(eng.Dispose);
                eng.CreateDatabase();
                cleanup.Start();
            }
            catch (Exception e)
            {
                EventLogging.WriteError(e);
            }

            connection.Open();
            var usersDB =
                new SqlCeCommand(
                    "CREATE TABLE Users_DB("
                    + "UserID int IDENTITY (100,1) NOT NULL UNIQUE, "
                    + "UserName nvarchar(128) NOT NULL UNIQUE, "
                    + "PassHash nvarchar(128) NOT NULL, "
                    + "Friends varbinary(5000), "
                    + "PRIMARY KEY (UserID));",
                    connection);
            usersDB.ExecuteNonQuery();
            usersDB.Dispose();
            connection.Dispose();
            connection.Close();
        }
开发者ID:novaksam,项目名称:CIS499_C-_IM_Package,代码行数:34,代码来源:DBInteract.cs

示例4: DatabaseSpecificSetUp

        public override void DatabaseSpecificSetUp()
        {
            string filePath = string.Concat(Path, "\\UmbracoPetaPocoTests.sdf");

            if (!File.Exists(filePath))
            {
                try
                {
                    //Delete database file before continueing                    
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }
                catch (Exception)
                {
                    //if this doesn't work we have to make sure everything is reset! otherwise
                    // well run into issues because we've already set some things up
                    TearDown();
                    throw;
                }

                //Create the Sql CE database
                //Get the connectionstring settings from config
                var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName];
                var engine = new SqlCeEngine(settings.ConnectionString);
                engine.CreateDatabase();
            }
            else
            {
                TestHelper.ClearDatabase();
            }
            
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:34,代码来源:SqlCeUpgradeTest.cs

示例5: CreateDatabase

 private static void CreateDatabase()
 {
     if (File.Exists(_fileName))
         File.Delete(_fileName);
     using (var engine = new SqlCeEngine(_connectionString))
         engine.CreateDatabase();
 }
开发者ID:statianzo,项目名称:MultiThreadFileAccessWebApp,代码行数:7,代码来源:DataAccess.cs

示例6: CompactDatabase

 public void CompactDatabase(string connectionString)
 {
     using (SqlCeEngine engine = new SqlCeEngine(connectionString))
     {
         engine.Compact(null);
     }
 }
开发者ID:inickvel,项目名称:SqlCeToolbox,代码行数:7,代码来源:SqlCeHelper.cs

示例7: Database

        public Database()
        {
            //Data Source=Mobile Device\SD-MMC Card\EnviDATA.sdf;Persist Security Info=True

            // Create new database
            try
            {
                m_FilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            }
            catch (Exception ex)
            {
                //Silent catch
                //ClassLibrary.Global.HandleError(null, ex);
                MessageBox.Show(ex.Message);
            }

            string _Path = string.Format("{0}\\{1}", m_FilePath, m_FileName);
            if (!File.Exists(_Path))
            {
                //check
            }

            m_ConectionString = string.Format("Data Source={0};Persist Security Info=True;Password ='{1}'", _Path, m_Password);

            m_Engine = new SqlCeEngine(m_ConectionString);

            Database.CheckIntegrity();
        }
开发者ID:slay22,项目名称:TrainstationAdvisor,代码行数:28,代码来源:DataBase.cs

示例8: TestConnection

        private void TestConnection(bool showMessage)
        {
            try
            {
                if (createDb)
                {
                    if (!System.IO.File.Exists(builder.DataSource))
                    {
                        using (var eng = new SqlCeEngine(builder.ConnectionString))
                        {
                            eng.CreateDatabase();
                        }
                    }
                }

                using (var conn = new SqlCeConnection(builder.ConnectionString))
                {
                    conn.Open();
                    this.ConnectionString = builder.ConnectionString;
                    if (showMessage)
                    {
                        MessageBox.Show("Test succeeded!");
                    }
                    else
                    {
                        this.DialogResult = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Helpers.DataConnectionHelper.ShowErrors(ex));
            }
        }
开发者ID:inickvel,项目名称:SqlCeToolbox,代码行数:34,代码来源:ConnectionDialog.xaml.cs

示例9: RepairDatabaseRecoverAllOrFail

 public void RepairDatabaseRecoverAllOrFail(string connectionString)
 {
     using (SqlCeEngine engine = new SqlCeEngine(connectionString))
     {
         engine.Repair(connectionString, RepairOption.RecoverAllOrFail);
     }
 }
开发者ID:inickvel,项目名称:SqlCeToolbox,代码行数:7,代码来源:SqlCeHelper.cs

示例10: EnsureDatabase

        public void EnsureDatabase()
        {
            try
            {
                if (sqlCeFilePath.Length > 0)
                {
                    
                    //string connectionString = "Data Source=" + sqlCeFilePath + ";Persist Security Info=False;";

                    if (!File.Exists(sqlCeFilePath))
                    {
                        lock (theLock)
                        {
                            if (!File.Exists(sqlCeFilePath))
                            {
                                using (SqlCeEngine engine = new SqlCeEngine(connectionString))
                                {
                                    engine.CreateDatabase();
                                }
                            }

                        }

                    }

                }
            }
            catch (Exception ex)
            {
                log.LogError("SqlCe database file is not present, tried to create it but this error occurred.", ex);

            }

        }
开发者ID:ruelbtit2014,项目名称:cloudscribe,代码行数:34,代码来源:Db.cs

示例11: Compact

 /// <summary>
 /// Reclaims wasted space in the database and recalculates identity column values. Applies only to SQL CE.
 /// </summary>
 internal static void Compact()
 {
     using (SqlCeEngine engine = new SqlCeEngine(Util.ConnectionString))
     {
         engine.Compact(null);
     }
 }
开发者ID:xusun,项目名称:GalleryServerPro,代码行数:10,代码来源:DataUtility.cs

示例12: CreateDatabase

        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates SQL Server CE database using specified file path.
        /// Executes SQL script using specified script value if not null.
        /// </summary>
        /// <param name="path">
        /// Database file path.
        /// </param>
        /// <param name="createScript">
        /// Transact SQL script to execute. Optional (can be null).
        /// Provided script must conform to SQL Server CE.
        /// </param>
        public static void CreateDatabase(string path, string createScript)
        {
            Debug.Assert(path != null);

            bool dbCreated = false;
            try
            {
                // check if specified file exists
                if (File.Exists(path))
                    throw new DataException(Properties.Messages.Error_DbFileExists);

                // build connection string
                string connStr = DatabaseHelper.BuildSqlConnString(path, false);

                // create database
                SqlCeEngine engine = new SqlCeEngine(connStr);
                engine.CreateDatabase();
                dbCreated = true;

                // execute SQL script
                if (createScript != null)
                    ExecuteScript(connStr, createScript, null);
            }
            catch (Exception e)
            {
                Logger.Error(e);

                if (dbCreated)
                    DeleteDatabase(path);

                throw;
            }
        }
开发者ID:erindm,项目名称:route-planner-csharp,代码行数:46,代码来源:DatabaseEngine.cs

示例13: RunApplication

		public void RunApplication(string[] args)
		{
			// example command line args: 
			// ClearCanvas.Dicom.DataStore.SetupApplication.Application "<TrunkPath>\Dicom\DataStore\AuxiliaryFiles\empty_viewer.sdf" "<TrunkPath>\Dicom\DataStore\AuxiliaryFiles\CreateTables.clearcanvas.dicom.datastore.ddl"

			string databaseFile = args[0];
			string scriptFile = args[1];

			File.Delete(databaseFile);

			string connectionString = String.Format("Data Source=\"{0}\"", databaseFile);

			SqlCeEngine engine = new SqlCeEngine(connectionString);
			engine.CreateDatabase();
			engine.Dispose();

			StreamReader reader = new StreamReader(scriptFile);
			string scriptText = reader.ReadToEnd();
			reader.Close();

			SqlCeConnection connection = new SqlCeConnection(connectionString);
			connection.Open();

			SqlCeTransaction transaction = connection.BeginTransaction();
			SqlCeCommand command = new SqlCeCommand();
			command.Connection = connection;
			command.CommandText = scriptText;
			command.ExecuteNonQuery();

			transaction.Commit();
			connection.Close();

		}
开发者ID:khaha2210,项目名称:radio,代码行数:33,代码来源:Application.cs

示例14: TestFixtureSetup

        public void TestFixtureSetup()
        {
            // Initialize the database.

            if (File.Exists("Test.sdf")) {
                File.Delete("Test.sdf");
            }

            using (var engine = new SqlCeEngine(ConfigurationManager.ConnectionStrings["Test"].ConnectionString)) {
                engine.CreateDatabase();
            }

            using (var conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString)) {
                var cmd = conn.CreateCommand();
                conn.Open();

                cmd.CommandText = "create table Users (Id int identity, Name nvarchar(250))";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "create table ManualIdUser (Id int, Name nvarchar(250))";
                cmd.ExecuteNonQuery();

                cmd.CommandText =
                    "create table CompositeKeyUser (Id int not null, Id2 nvarchar(250) not null, Name nvarchar(250), primary key (Id, Id2)) ";
                cmd.ExecuteNonQuery();
            }
        }
开发者ID:JeremySkinner,项目名称:SimpleQuery,代码行数:27,代码来源:BaseTest.cs

示例15: Can_Assert_Created_Database

        public void Can_Assert_Created_Database()
        {
            string path = TestHelper.CurrentAssemblyDirectory;
            AppDomain.CurrentDomain.SetData("DataDirectory", path);

            //Delete database file before continueing
            string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf");
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            //Get the connectionstring settings from config
            var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName];

            //Create the Sql CE database
            var engine = new SqlCeEngine(settings.ConnectionString);
            engine.CreateDatabase();

            SqlSyntaxContext.SqlSyntaxProvider = SqlCeSyntax.Provider;

            //Create the umbraco database
			_dbContext.Database.CreateDatabaseSchema(false);

			bool umbracoNodeTable = _dbContext.Database.TableExist("umbracoNode");
			bool umbracoUserTable = _dbContext.Database.TableExist("umbracoUser");
			bool cmsTagsTable = _dbContext.Database.TableExist("cmsTags");

            Assert.That(umbracoNodeTable, Is.True);
            Assert.That(umbracoUserTable, Is.True);
            Assert.That(cmsTagsTable, Is.True);
        }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:32,代码来源:DatabaseContextTests.cs


注:本文中的SqlCeEngine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。