public LiteDbRepository(DbConnectionModel config) { //ILiteDbConnection connection var connection = new LiteDbConnection(config); _dbConnection = connection.Connection; }
public LiteDbConnection(DbConnectionModel dbConnection) { //var dbConnection = IoC.Resolve<DbConnectionModel>(""); var config = dbConnection as LiteDbConnectionConfig; Connection = new LiteDatabase(config.ConnectionString); }
public List <TableModel> GetTables(DbConnectionModel form) { if (!ConnectionTest(form)) { return(new List <TableModel>()); } var sql = @" SELECT OBJECT_ID(TABLE_NAME) ID, Table_Catalog TableCatalog, Table_Name TableName, Table_Schema TableSchema, Table_Type TableType, ISNULL((SELECT TOP(1) ex.value FROM sys.extended_properties ex WHERE OBJECT_ID(TABLE_NAME) = ex.major_id AND ex.minor_id=0 AND name = 'MS_Description'),TABLE_NAME) N'Description' FROM INFORMATION_SCHEMA.TABLES"; var tables = _dbUtil.GetList <TableModel>(sql); tables.ForEach(x => x.Columns = GetColumns(x) ?? new List <ColumnsModel>()); tables.ForEach(x => x.TableConstraints = GetTableConstraints(x) ?? new List <TableConstraintModel>()); return(tables.ToList()); }
private void TestConn(object parameter) { try { PasswordBox passwordBox = (PasswordBox)parameter; this.Password = passwordBox.Password; if (!CheckValid()) { MessageBoxHelper.MessageBoxShowWarning("请填写完整的数据库配置信息!"); return; } DbConnectionModel conn = this.GetDbConnectionModel(); if (MSSqlHelper.TestDbConnection(conn.ConnectionStr)) { CanExecute = true; ShowMessage("数据库连接成功"); Notice.Show("数据库连接成功", "通知", 3, MessageBoxIcon.Success); } else { CanExecute = false; MessageBoxHelper.MessageBoxShowWarning("连接错误,请重新输入数据库连接信息"); } } catch (Exception ex) { MessageBoxHelper.MessageBoxShowWarning("连接错误,请重新输入JSDS数据库连接信息"); } }
public void CreateConnectionOption(int id, string datasource, string userID, string password, string initialCatalog) { var dbConnectionModel = new DbConnectionModel { Id = id, DataSource = datasource, UserID = userID, Password = password, InitialCatalog = initialCatalog }; _dbConnectionContext.DbConnectionOptions.Add(dbConnectionModel); _dbConnectionContext.SaveChanges(); }
private static void ConfigureDatabases(IServiceCollection services, IConfiguration configuration) { var databaseConnectionSettings = new DbConnectionModel(); configuration.GetSection("DbConnectionSettings").Bind(databaseConnectionSettings); services.AddDbContextPool <DemoContext>(c => c.UseSqlServer(CreateConnectionString(databaseConnectionSettings), o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery).EnableRetryOnFailure( maxRetryCount: 4, maxRetryDelay: TimeSpan.FromSeconds(1), errorNumbersToAdd: new int[] { } )).EnableDetailedErrors()); }
public bool ConnectionTest(DbConnectionModel form) { try { _dbUtil.dbType = form.DbType; _dbUtil.connectionString = _dbUtil.GenerateConnectionString(form); _dbUtil.SetConnection(); return(true); } catch { return(false); } }
public string GenerateConnectionString(DbConnectionModel form) { string connectionString; switch (form.DbType) { case "MSSQL": connectionString = $"Data Source={form.DbServer};Initial Catalog={form.DbName};Persist Security Info=True;User ID={form.User};Password={form.Password}"; break; default: connectionString = ""; break; } return(connectionString); }
public RavenDbConnection(DbConnectionModel dbConnection) { if (_connection != null) { return; } //var config = appSetting.Get<RavenDbConnectionConfig>("DbConnection"); var config = dbConnection as RavenDbConnectionConfig; _connection = new DocumentStore() { Urls = config.Servers, Database = config.DatabaseName, Conventions = { } }; _connection.Initialize(); }
public static void SaveConnection(DbConnectionModel model) { if (string.IsNullOrEmpty(model.Id)) { model.Id = Guid.NewGuid().ToString(); } if (_savedConnections == null) { _savedConnections = new List <DbConnectionModel>(); } if (!_savedConnections.Any(a => a.Id == model.Id)) { _savedConnections.Add(model); } var _text = Newtonsoft.Json.JsonConvert.SerializeObject(_savedConnections); using (StreamWriter writer = new StreamWriter(_connectionDataPath, false)) { writer.Write(_text); } }
public RavenDbConnection(DbConnectionModel dbConnection) { if (_connection != null) { return; } //var config = appSetting.Get<RavenDbConnectionConfig>("DbConnection"); var config = dbConnection as RavenDbConnectionConfig; _connection = new DocumentStore() { Urls = config.Servers, Database = config.DatabaseName, Conventions = { FindCollectionName = type => { _tableTypes ??= Globals.GetClassTypeWithAttribute <TableAttribute>(); if (_tableTypes.All(t => t != type)) { return(DocumentConventions.DefaultGetCollectionName(type)); } var name = (type.GetCustomAttribute(typeof(TableAttribute)) as TableAttribute)?.Name; return(string.IsNullOrWhiteSpace(name) ? DocumentConventions.DefaultGetCollectionName(type) : name); } } }; _connection.Initialize(); }
private static string CreateConnectionString(DbConnectionModel databaseConnectionModel) { var builder = new SqlConnectionStringBuilder { DataSource = string.IsNullOrEmpty(databaseConnectionModel.Port) ? databaseConnectionModel.Host : databaseConnectionModel.Host + "," + databaseConnectionModel.Port, InitialCatalog = databaseConnectionModel.DatabaseName }; if (databaseConnectionModel.IntegratedSecurity) { builder.IntegratedSecurity = true; } else { builder.UserID = databaseConnectionModel.UserName; builder.Password = databaseConnectionModel.Password; } builder.MultipleActiveResultSets = databaseConnectionModel.MultipleActiveResultSets; return(builder.ConnectionString); }
public DapperRepository(DbConnectionModel config) { string provider; Dialect dialect; switch (((config as DapperConnectionConfig)?.Provider.ToLower())) { case "mysql": provider = "Dapper.MySQL"; dialect = Dialect.MySQL; break; case "postgresql": provider = "Dapper.PostgreSQL"; dialect = Dialect.PostgreSQL; break; case "sqlite": provider = "Dapper.SQLite"; dialect = Dialect.SQLite; break; case "sqlserver": default: provider = "Dapper.SQLServer"; dialect = Dialect.SQLServer; break; } var connection = IoC.Resolve <IDapperConnection>(provider, new { dbConnection = config }); _dapper = new DapperFramework(dialect); _connection = connection.Connection; _connection.Open(); //OpenTransaction(); }
public PostgreSqlConnection(DbConnectionModel dbConnection) { var config = dbConnection as DapperConnectionConfig; Connection = new NpgsqlConnection(config.ConnectionString); }
public JsonResult Post([FromBody] DbConnectionModel form) { var result = _dbService.ConnectionTest(form); return(new JsonResult(result)); }
private void simpleButtonConnect_Click(object sender, EventArgs e) { if (xtraTabControlMain.SelectedTabPageIndex == 0) // Postgresql { var model = new DbConnectionModel(); model.Alias = textEditAliasPostgres.Text.Trim(); model.Database = textEditDatabasePostgres.Text.Trim(); model.HostOrIp = textEditHostOrIPPostgres.Text.Trim(); model.Password = textEditPasswordPostgres.Text.Trim(); model.Port = int.Parse(textEditPortPostgres.Text.Trim()); model.Username = textEditUsernamePostgres.Text.Trim(); string _connectionString = "Server = " + model.HostOrIp + "; Port = " + model.Port + "; Database = " + model.Database + "; User Id = " + model.Username + "; Password = "******";"; try { using (NpgsqlConnection cnn = new NpgsqlConnection(_connectionString)) { cnn.Open(); NpgsqlDataAdapter da = new NpgsqlDataAdapter("Select 1", cnn); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { if (toggleSwitchSaveConnectionPostgres.IsOn) { if (!string.IsNullOrEmpty(_selectedConnectionId)) { AppHelper.RemoveConnection(_selectedConnectionId); } model.DatabaseType = Models.DbType.PostgreSQL; AppHelper.SaveConnection(model); this.Close(); } } else { XtraMessageBox.Show("Cannot connect to database. Please check"); this.DialogResult = DialogResult.None; } } } catch (Exception ex) { XtraMessageBox.Show("Cannot connect to database. Please check"); this.DialogResult = DialogResult.None; } } else if (xtraTabControlMain.SelectedTabPageIndex == 1) // Oracle { var tns = DxHelper.GetSelectedItem(comboBoxEditTnsNamesOracle); if (tns.Value.ToString() != "-1") { var model = new DbConnectionModel(); model.Alias = textEditAliasOracle.Text.Trim(); model.HostOrIp = tns.Text.Trim(); model.Password = textEditPasswordOracle.Text.Trim(); model.Username = textEditUsernameOracle.Text.Trim(); string _connectionString = "User Id=" + model.Username + ";Password="******";Data Source=" + model.HostOrIp + ";"; try { using (OracleConnection cnn = new OracleConnection(_connectionString)) { cnn.Open(); OracleDataAdapter da = new OracleDataAdapter("Select 1 from dual", cnn); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { if (toggleSwitchIsSaveConnectionOracle.IsOn) { if (!string.IsNullOrEmpty(_selectedConnectionId)) { AppHelper.RemoveConnection(_selectedConnectionId); } model.DatabaseType = Models.DbType.Oracle; AppHelper.SaveConnection(model); this.Close(); } } else { XtraMessageBox.Show("Cannot connect to database. Please check"); this.DialogResult = DialogResult.None; } } } catch (Exception ex) { XtraMessageBox.Show("Cannot connect to database. Please check"); this.DialogResult = DialogResult.None; } } } }
public SqliteConnection(DbConnectionModel dbConnection) { var config = dbConnection as DapperConnectionConfig; Connection = new SQLiteConnection(config.ConnectionString); }
public MySqlConnection(DbConnectionModel dbConnection) { var config = dbConnection as DapperConnectionConfig; Connection = new MySql.Data.MySqlClient.MySqlConnection(config.ConnectionString); }
public RavenDbRepository(DbConnectionModel config) { _dbConnection = new RavenDbConnection(config); Session = _dbConnection.Connection.OpenAsyncSession(); }