zoukankan      html  css  js  c++  java
  • 连接数据库

    private string connectionString;
            private void SaveCustomerInfo() {
                var entityConnStr = ConfigurationManager.ConnectionStrings["DcsEntities"].ConnectionString;
                if(!string.IsNullOrEmpty(entityConnStr)) {
                    var entityConnection = new EntityConnectionStringBuilder(entityConnStr);
                    this.connectionString = entityConnection.ProviderConnectionString;
                }
                var db = DbHelper.GetDbHelp(this.connectionString);
                var sqlInsert = db.GetInsertSql("reportquerylog ", "Id", new[] {
                                    "UserId","EnterpriseId","CreateTime","PageName"
                                });
     
                using(var conn = db.CreateDbConnection()) {
                    conn.Open();
                    var ts = conn.BeginTransaction();
                    try {
                        var cmd = db.CreateDbCommand(sqlInsert, conn, null);
                       // cmd.Parameters.Add(db.CreateDbParameter("Id", Guid.NewGuid()));
                        cmd.Parameters.Add(db.CreateDbParameter("UserId", Utils.GetCurrentUserInfo().LoginId));
                        cmd.Parameters.Add(db.CreateDbParameter("EnterpriseId", Utils.GetCurrentUserInfo().EnterpriseId));
                        cmd.Parameters.Add(db.CreateDbParameter("CreateTime", DateTime.Now));
                        cmd.Parameters.Add(db.CreateDbParameter("PageName", "23"));
                        cmd.ExecuteNonQuery();
                        ts.Commit();
     
                    } catch(Exception) {
                        ts.Rollback();
                    } finally {
                        conn.Close();
                    }
                }
            }
  • 相关阅读:
    Jmeter 之 上传下载文件
    Jmeter 样例 之 JDBC请求-操作MySql数据库
    Jmeter综合运用 之 接口测试
    Jmeter 逻辑控制器 之 Switch Controller
    Jmeter 逻辑控制器 之 吞吐量控制器
    Win10系统,Jmeter 字体调整方法
    Jmeter 逻辑控制器 之 交替控制器
    Jmeter 逻辑控制器 之 Runtime Controller
    Jmeter 逻辑控制器 之 Include Controller
    Jmeter 逻辑控制器 之 ForEach 控制器
  • 原文地址:https://www.cnblogs.com/naliang/p/5573296.html
Copyright © 2011-2022 走看看