Пример #1
0
        void ExecuteSql2(string sql)
        {
            var ds = new DBServer();

            ds.ExecNonQuery(sql);
            ds.Dispose();
            ds = null;
        }
Пример #2
0
        protected void RestoreDb()
        {
            string sql = @"use master  
declare @dbname sysname 
set @dbname='Option-test' --这个是要删除的数据库库名

declare @s nvarchar(1000) 
declare tb cursor local for 
select s='kill '+cast(spid as varchar) 
from master..sysprocesses 
where dbid=db_id(@dbname) 
open tb 
fetch next from tb into @s 
while @@fetch_status=0 
begin 
exec(@s) 
fetch next from tb into @s 
end 
close tb 
deallocate tb 
exec('drop database ['+@dbname+']')";

            var ds = new DBServer(@"Data Source=.\sqlexpress;Initial Catalog=master;Integrated Security=True");

            ds.ExecNonQuery(sql);
            ds.Dispose(); ds = null;



            //Database.SetInitializer<OptionDbCtx>(new DropCreateDatabaseAlways<OptionDbCtx>());

            var context = new OptionDbCtx();

            context.Database.Initialize(true);
            //if (!context.Database.Exists())
            //{
            //    context.Database.Create();
            //}
            //var initor = new TraderInitor();
            //initor.Init(context);

            //var ci = new ContractInitor();
            //ci.Init(context);
        }
Пример #3
0
        void RestoreDb()
        {
            string sql = @"
USE [master]
/****** Object:  Database [Option-test]    Script Date: 11/26/2014 11:17:06 ******/
DROP DATABASE [Option-test]";
            var    ds  = new DBServer(@"Data Source=.\sqlexpress;Initial Catalog=master;Integrated Security=True");

            ds.ExecNonQuery(sql);
            ds.Dispose(); ds = null;

            var context = new OptionDbCtx();
            var initor  = new TraderInitor();

            initor.Init(context);

            //var ci = new ContractInitor();
            //ci.Init(context);
        }