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


C# SqlCeEngine.CreateDatabase方法代码示例

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


在下文中一共展示了SqlCeEngine.CreateDatabase方法的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: CreateDBConnection

        public static SqlCeConnection CreateDBConnection()
        {
            if (!File.Exists(Path.Combine(Application.StartupPath, "db.sdf")))
            {
                using (SqlCeEngine eng = new SqlCeEngine(dbPath))
                    eng.CreateDatabase();
                using (SqlCeConnection conn = new SqlCeConnection(dbPath))
                {
                    conn.Open();
                    using (SqlCeCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "CREATE TABLE [Beatmaps] " +
                                          "(" +
                                          "[Hash] nvarchar(32) NOT NULL, " +
                                          "[Filename] nvarchar(500) NOT NULL" +
                                          ")";
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = "ALTER TABLE [Beatmaps] ADD CONSTRAINT [PK_Beatmaps] PRIMARY KEY ([Hash]) ";
                        cmd.ExecuteNonQuery();
                    }
                }

            }
            return new SqlCeConnection(dbPath);
        }
开发者ID:smoogipooo,项目名称:osu-Replay-Analyzer,代码行数:25,代码来源:DBHelper.cs

示例5: CreateDatabaseIfRequired

        public static void CreateDatabaseIfRequired(string connection, string applicationName)
        {
            string dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string;

            string physConnectionString = connection.Replace("|DataDirectory|" + System.IO.Path.DirectorySeparatorChar, dataDirectory +  System.IO.Path.DirectorySeparatorChar);

            physConnectionString = physConnectionString.Replace("|DataDirectory|", dataDirectory + System.IO.Path.DirectorySeparatorChar);

            string sdfPath = string.Empty;
            lock (_lock)
            {
                SqlCeConnectionStringBuilder builder = new SqlCeConnectionStringBuilder();
                builder.ConnectionString = physConnectionString;

                sdfPath = builder.DataSource;

                if (string.IsNullOrWhiteSpace(sdfPath))
                    return;

                if (!System.IO.File.Exists(sdfPath))
                {
                    //OK, try to create the database file
                    using (var engine = new SqlCeEngine(connection))
                    {
                        engine.CreateDatabase();
                    }
                }
                ValidateDatabase(connection, applicationName);

            }
        }
开发者ID:brianlpope,项目名称:MediumTrustMVCWebsite,代码行数:31,代码来源:SqlCeMembershipUtils.cs

示例6: CreateDatabase

 /// <summary>
 /// 创建新数据源。
 /// </summary>
 public void CreateDatabase()
 {
     using(SqlCeEngine engine = new SqlCeEngine(this.ConnectionString))
     {
         engine.CreateDatabase();
     }
 }
开发者ID:glorylee,项目名称:Aoite,代码行数:10,代码来源:SqlCeEngineProvider.cs

示例7: Initialize

        public override void Initialize(string name, NameValueCollection config)
        {
            try
            {
                // Initialize connection string.
                string path = config["path"];
                if (string.IsNullOrEmpty(path))
                    path = "~/App_Data/DynamicImage/DynamicImageCache.sdf";
                string absolutePath = HttpContext.Current.Server.MapPath(path);
                if (!Directory.Exists(Path.GetDirectoryName(absolutePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(absolutePath));
                _connectionString = string.Format("Data Source={0}", absolutePath);
                if (!File.Exists(absolutePath))
                {
                    using (SqlCeEngine en = new SqlCeEngine(_connectionString))
                        en.CreateDatabase();

                    UseConnection(conn =>
                    {
                        using (DbCommand comm = conn.CreateCommand())
                        {
                            // Create the Version table if it doesn't already exist.
                            comm.CommandText = "CREATE TABLE Version (VersionNumber INT)";
                            comm.ExecuteNonQuery();
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException("Could not initialize connection string.", ex);
            }

            base.Initialize(name, config);
        }
开发者ID:dbre2,项目名称:dynamic-image,代码行数:35,代码来源:SqlCeCacheProvider.cs

示例8: ctlrptActiveCall

        public ctlrptActiveCall()
        {
            try
            {
                InitializeComponent();

                ConnectionString = VMuktiAPI.VMuktiInfo.MainConnectionString;
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.ToString() + "rptActiveCall.sdf"))
                {
                    System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory.ToString() + "rptActiveCall.sdf");
                }
                SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
                clientEngine.CreateDatabase();
                LocalSQLConn = new SqlCeConnection();
                LocalSQLConn.ConnectionString = ClientConnectionString;
                LocalSQLConn.Open();
                fncActiveCallTable();
                LocalSQLConn.Close();

                objRefreshReport = new delRefreshReport(fncRefreshReport);
                NetPeerClient npcActiveCall = new NetPeerClient();
                ((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcJoinCall += new NetP2PBootStrapActiveCallReportDelegates.DelsvcJoinCall(ctlrptActiveCall_EntsvcJoinCall);
                ((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcGetCallInfo += new NetP2PBootStrapActiveCallReportDelegates.DelsvcGetCallInfo(ctlrptActiveCall_EntsvcGetCallInfo);
                ((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcActiveCalls += new NetP2PBootStrapActiveCallReportDelegates.DelsvcActiveCalls(ctlrptActiveCall_EntsvcActiveCalls);
                ((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcSetDuration += new NetP2PBootStrapActiveCallReportDelegates.DelsvcSetDuration(ctlrptActiveCall_EntsvcSetDuration);
                ((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcUnJoinCall += new NetP2PBootStrapActiveCallReportDelegates.DelsvcUnJoinCall(ctlrptActiveCall_EntsvcUnJoinCall);
                channelNetTcpActiveCall = (INetP2PBootStrapReportChannel)npcActiveCall.OpenClient<INetP2PBootStrapReportChannel>("net.tcp://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + ":6000/NetP2PBootStrapActiveCallReport", "ActiveCallMesh", ref objActiveCall);
                channelNetTcpActiveCall.svcJoinCall(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName);

            }
            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "ctlrptActiveCall", "ctlrptActiveCall.xaml.cs");
            }
        }
开发者ID:jiangguang5201314,项目名称:VMukti,代码行数:35,代码来源:ctlrptActiveCall.xaml.cs

示例9: 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

示例10: CreateDatabaseIfRequired

        public static void CreateDatabaseIfRequired(string connection, string applicationName)
        {
            lock (_lock)
            {
                SqlCeConnectionStringBuilder builder = new SqlCeConnectionStringBuilder();
                builder.ConnectionString = connection;

                string sdfPath = ReplaceDataDirectory(builder.DataSource);

                if (string.IsNullOrWhiteSpace(sdfPath))
                    return;

                if (!System.IO.File.Exists(sdfPath))
                {
                    //OK, try to create the database file
                    using (var engine = new SqlCeEngine(connection))
                    {
                        engine.CreateDatabase();
                    }

                                        Util.ExecuteSqlUpgradeScript(GalleryDataSchemaUpgradeScript.SqlCeInstallScript);
                                }
                ValidateDatabase(connection, applicationName);

            }
        }
开发者ID:raquelsa,项目名称:GalleryServerProWeb,代码行数:26,代码来源:SqlCeMembershipUtils.cs

示例11: 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

示例12: 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

示例13: CreateDatabase

 public static void CreateDatabase(string dataFile, string connectionString)
 {
     var dir = Path.GetDirectoryName(dataFile);
     IO.IOUtility.EnsureDirectoryExists(dir);
     SqlCeEngine engine = new SqlCeEngine(connectionString);
     engine.CreateDatabase();
 }
开发者ID:Godoy,项目名称:CMS,代码行数:7,代码来源:DatabaseHelper.cs

示例14: CreateDatabaseSchema

        /// <summary>
        /// Private method to install the umbraco database schema in an empty database
        /// </summary>
        /// <param name="database"></param>
        /// <param name="databaseProvider"></param>
        /// <param name="dataDirectory"></param>
        private static void CreateDatabaseSchema(Database database, DatabaseProviders databaseProvider, string dataDirectory)
        {
            Console.WriteLine("Please note that installing the umbraco database schema requires an empty database configured in config.");
            Console.WriteLine("The 'umbracoConfigurationStatus' under appSettings should be left blank.");
            Console.WriteLine("If you are using Sql Ce an empty Umbraco.sdf file should exist in the DataDictionary.");
            Console.WriteLine("Press y to continue");

            var input = Console.ReadLine();
            if (string.IsNullOrEmpty(input) == false && input.ToLowerInvariant().Equals("y"))
            {
                try
                {
                    if (databaseProvider == DatabaseProviders.SqlServerCE)
                    {
                        var dbPath = Path.Combine(dataDirectory, "Umbraco.sdf");
                        if (File.Exists(dbPath) == false)
                        {
                            var engine = new SqlCeEngine(@"Data Source=|DataDirectory|\Umbraco.sdf;Flush Interval=1;");
                            engine.CreateDatabase();
                        }
                    }

                    database.CreateDatabaseSchema(false);

                    Console.WriteLine("The database schema has been installed");
                    Console.WriteLine("Note: This is just an example, so no backoffice user has been created.");
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occured while trying to install the database schema");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                }
            }
        }
开发者ID:anders12e,项目名称:umbraco-console-example,代码行数:41,代码来源:Program.cs

示例15: Initialize

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

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

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

            //Create the Sql CE database
            var engine = new SqlCeEngine("Datasource=|DataDirectory|test.sdf");
            engine.CreateDatabase();

            RepositoryResolver.Current = new RepositoryResolver(
                new RepositoryFactory());

            Resolution.Freeze();
            ApplicationContext.Current = new ApplicationContext(
                //assign the db context
                new DatabaseContext(new DefaultDatabaseFactory()),
                //assign the service context
                new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true };

            SqlSyntaxContext.SqlSyntaxProvider = SqlCeSyntax.Provider;

            _database = new Database("Datasource=|DataDirectory|test.sdf",
                                     "System.Data.SqlServerCe.4.0");
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:34,代码来源:SqlCeTableByTableTest.cs


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