コード例 #1
0
ファイル: Program.cs プロジェクト: olekongithub/synctoday2015
        public static void PurgeDb(Seed seed)
        {
            ConnectionProfile cp = new ConnectionProfile();
            SqlConnectionStringBuilder conn_orig = new SqlConnectionStringBuilder(cp.ConnectionString);
            SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder(cp.ConnectionString) { ConnectTimeout = 5, InitialCatalog = "master" }; // you can add other parameters.
            using (SqlConnection cnn = new SqlConnection(conn.ConnectionString))
            {
                cnn.Open();

                using (SqlCommand dbCreate = new SqlCommand())
                {
                    dbCreate.CommandText = string.Format(@"IF db_id('{0}') IS NULL CREATE DATABASE [{0}]", conn_orig.InitialCatalog);
                    dbCreate.Connection = cnn;
                    try
                    {
                        dbCreate.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("create database [{0}] FAILED with {1}", conn_orig.InitialCatalog, ex.Message ));
                    }
                }
            }

            seed.PurgeDb();
        }
コード例 #2
0
ファイル: Seed.cs プロジェクト: jaseporter01/DNUG
 public Seed(ConnectionProfile connectionProfile)
 {
     if (connectionProfile == null)
     {
         connectionProfile = new ConnectionProfile();
     }
     ConnectionProfile = connectionProfile;
 }
コード例 #3
0
ファイル: Query.cs プロジェクト: adamjmoon/Restful
        public static void InsertInto(this object o, string table, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null) connectionProfile = new ConnectionProfile();

            DynamicModel dynamicModel = new DynamicModel(connectionProfile, table, "Id");

            dynamicModel.Insert(o);
        }
コード例 #4
0
ファイル: Query.cs プロジェクト: kujotx/Oak
        public static object InsertInto(this object o, string table, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null) connectionProfile = new ConnectionProfile();

            DynamicRepository dynamicModel = new DynamicRepository(connectionProfile, table, "Id");

            return dynamicModel.Insert(o);
        }
コード例 #5
0
ファイル: Query.cs プロジェクト: adamjmoon/Restful
        public static SqlDataReader ExecuteReader(this string query, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null) connectionProfile = new ConnectionProfile();

            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = new SqlConnection(connectionProfile.ConnectionString);
            sqlCommand.Connection.Open();
            sqlCommand.CommandText = String.Format(query);
            return sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
        }
コード例 #6
0
ファイル: Massive.cs プロジェクト: amirrajan/LoamNancy
        public static object InsertInto(this object o, string table, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null)
            {
                connectionProfile = new ConnectionProfile();
            }

            DynamicRepository dynamicModel = new DynamicRepository(connectionProfile, table, "Id");

            return(dynamicModel.Insert(o));
        }
コード例 #7
0
ファイル: Query.cs プロジェクト: adamjmoon/Restful
        public static void ExecuteNonQuery(this string query, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null) connectionProfile = new ConnectionProfile();

            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = new SqlConnection(connectionProfile.ConnectionString);
            sqlCommand.Connection.Open();
            sqlCommand.CommandText = String.Format(query);
            sqlCommand.ExecuteNonQuery();
            sqlCommand.Connection.Close();
        }
コード例 #8
0
ファイル: Massive.cs プロジェクト: pgermishuys/Oak
        public DynamicRepository(ConnectionProfile connectionProfile, string tableName = "", string primaryKeyField = "")
        {
            TableName = tableName == "" ? this.GetType().Name : tableName;
            PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "Id" : primaryKeyField;
            var _providerName = "System.Data.SqlClient";
            _factory = DbProviderFactories.GetFactory(_providerName);

            if (connectionProfile == null) connectionProfile = new ConnectionProfile();
            ConnectionProfile = connectionProfile;
            Projection = (d) => d;
        }
コード例 #9
0
ファイル: Query.cs プロジェクト: adamjmoon/Restful
        public static object ExecuteScalar(this string query, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null) connectionProfile = new ConnectionProfile();

            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = new SqlConnection(connectionProfile.ConnectionString);
            sqlCommand.Connection.Open();
            sqlCommand.CommandText = String.Format(query);
            var result = sqlCommand.ExecuteScalar();
            sqlCommand.Connection.Close();

            return result;
        }
コード例 #10
0
        public static SqlDataReader ExecuteReader(this string query, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null)
            {
                connectionProfile = new ConnectionProfile();
            }

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.Connection = new SqlConnection(connectionProfile.ConnectionString);
            sqlCommand.Connection.Open();
            sqlCommand.CommandText = String.Format(query);
            return(sqlCommand.ExecuteReader(CommandBehavior.CloseConnection));
        }
コード例 #11
0
        public static void ExecuteNonQuery(this string query, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null)
            {
                connectionProfile = new ConnectionProfile();
            }

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.Connection = new SqlConnection(connectionProfile.ConnectionString);
            sqlCommand.Connection.Open();
            sqlCommand.CommandText = String.Format(query);
            sqlCommand.ExecuteNonQuery();
            sqlCommand.Connection.Close();
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: eugman/Oak
        static void Main(string[] args)
        {
            if (args.Length == 0) throw new InvalidOperationException("first argument should be a connection string.");

            Console.WriteLine("Purging and regenerating schema for " + args[0] + ".");

            var connection = new ConnectionProfile { ConnectionString = args[0] };

            var seed = new Seed(connection);

            var schema = new Schema(seed);

            seed.PurgeDb();

            seed.ExecuteTo(schema.Scripts(), schema.Current());

            Console.WriteLine("Done.");
        }
コード例 #13
0
        public static object ExecuteScalar(this string query, ConnectionProfile connectionProfile = null)
        {
            if (connectionProfile == null)
            {
                connectionProfile = new ConnectionProfile();
            }

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.Connection = new SqlConnection(connectionProfile.ConnectionString);
            sqlCommand.Connection.Open();
            sqlCommand.CommandText = String.Format(query);
            var result = sqlCommand.ExecuteScalar();

            sqlCommand.Connection.Close();

            return(result);
        }
コード例 #14
0
ファイル: Seed.cs プロジェクト: olekongithub/synctoday2015
 public Seed(ConnectionProfile connectionProfile)
 {
     if (connectionProfile == null) connectionProfile = new ConnectionProfile();
     ConnectionProfile = connectionProfile;
 }
コード例 #15
0
ファイル: DynamicDb.cs プロジェクト: eugman/Oak
 public DynamicDb()
 {
     connectionString = new ConnectionProfile().ConnectionString;
 }