public string GetConnectionString(SqlDbConfig config, string user, string password) { if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(password)) { if (!(String.IsNullOrEmpty(user) && String.IsNullOrEmpty(password))) { throw new Exception("BUG: user and password must both be empty when one is."); } if (String.IsNullOrEmpty(config.Database.Connection.DefaultUser) || String.IsNullOrEmpty(config.Database.Connection.DefaultPassword)) { throw new Exception("Please add DefaultUser and DefaultPassword"); } return(GetConnectionString(config, config.Database.Connection.DefaultUser, config.Database.Connection.DefaultPassword)); } else { var db = config.Database; string tmp1 = string.Copy(db.Connection.ConnectionString); DbConnectionStringBuilder connBuilder = new DbConnectionStringBuilder(); connBuilder.ConnectionString = tmp1; if (connBuilder.ContainsKey(db.Connection.KeyForPassword)) { connBuilder.Remove(db.Connection.KeyForPassword); connBuilder.Add(db.Connection.KeyForPassword, password); } if (connBuilder.ContainsKey(db.Connection.KeyForUser)) { connBuilder.Remove(db.Connection.KeyForUser); connBuilder.Add(db.Connection.KeyForUser, user); } return(connBuilder.ConnectionString); } }
private static DbConnectionStringBuilder GetBuilder(string serverNameOrConnectionString) { // Special handling of a connection string on the form: "powerbi://api.powerbi.com/v1.0/myorg/workspace;initial catalog=dbname" if (serverNameOrConnectionString.StartsWith("powerbi://", StringComparison.OrdinalIgnoreCase) && serverNameOrConnectionString.Contains(";")) { serverNameOrConnectionString = "Provider=MSOLAP;Data Source=" + serverNameOrConnectionString; } DbConnectionStringBuilder csb = new DbConnectionStringBuilder(); if (serverNameOrConnectionString.Contains("=")) { try { csb.ConnectionString = serverNameOrConnectionString; } catch (ArgumentException) { } } if (!csb.ContainsKey(ProviderKey)) { csb.Add(ProviderKey, "MSOLAP"); } if (!csb.ContainsAny(DataSourceKey, "DataSource")) { csb.Add(DataSourceKey, serverNameOrConnectionString); } return(csb); }
/// <summary> /// Ham nay de mo ket noi den database /// </summary> /// <param name="ServerName"></param> /// <param name="DatabaseName"></param> /// <param name="UserId"></param> /// <param name="Password"></param> /// <returns></returns> public static bool DB_OpenConnection(string ServerName, string DatabaseName, string UserId, string Password) { DbProviderFactory = System.Data.SqlClient.SqlClientFactory.Instance; DbConnectionStringBuilder DbConnectionStringBuilder = DbProviderFactory.CreateConnectionStringBuilder(); DbConnectionStringBuilder.Add("Data Source", ServerName); DbConnectionStringBuilder.Add("User ID", UserId); DbConnectionStringBuilder.Add("Password", Password); DbConnectionStringBuilder.Add("Initial Catalog", DatabaseName); bool IsConnected; try { if (DbConnection == null) { DbConnection = DbProviderFactory.CreateConnection(); } if (DbConnection.State != ConnectionState.Open) { DbConnection.ConnectionString = DbConnectionStringBuilder.ConnectionString; DbConnection.Open(); } IsConnected = true; } catch { IsConnected = false; } return(IsConnected); }
/// <summary> /// Returns the best alias for <paramref name="keyword"/> or null if there are no known aliases. This is because some builders allow multiple keys for changing the same underlying /// property. /// </summary> /// <param name="keyword"></param> /// <param name="value"></param> /// <returns></returns> private string GetCollisionWithKeyword(string keyword, string value) { //lets evaluate this alleged keyword! _builder.Clear(); try { //Make sure it is supported by the connection string builder _builder.Add(keyword, value); }catch (Exception ex) { //don't output the value since that could be a password throw new ArgumentException(string.Format(FAnsiStrings.ConnectionStringKeyword_ValueNotSupported, keyword), ex); } //now iterate all the keys we had before and add those too, if the key count doesn't change for any of them we know it's a duplicate semantically if (_builder.Keys != null) { foreach (var current in _keywords) { int keysBefore = _builder.Keys.Count; _builder.Add(current.Key, current.Value.Item1); //key count in builder didn't change dispite there being new values added if (_builder.Keys.Count == keysBefore) { return(current.Key); } } } //no collisions return(null); }
public DbConnection CreateConnexion() { //fonctoin générique qui ouvre la connection selon n'importa quel type de bdd (ici MySql) switch (bddType) { case connexionType.MaBaseOleDb: con = new OleDbConnection("maChaineDeConnexion"); break; case connexionType.MaBaseSqlServer: con = new SqlConnection("maChaineDeConnexion"); break; case connexionType.MaBaseMySql: //construction de la chaine de connection DbConnectionStringBuilder connBuilder = new DbConnectionStringBuilder(); connBuilder.Add("Database", "Projets_Etudes"); connBuilder.Add("Data Source", "192.168.2.250"); connBuilder.Add("User Id", "root_etudes"); connBuilder.Add("Password", "dB24zK6c"); con = new MySqlConnection(connBuilder.ConnectionString); break; } return(con); }
private void initialize(string path, bool hasHeaders, bool hasMixedData) { string fullPath = Path.GetFullPath(path); string extension = Path.GetExtension(path); if (!File.Exists(fullPath)) throw new FileNotFoundException("File could not be found.", fullPath); string tempFileName = Path.GetTempFileName(); File.Copy(fullPath, tempFileName, true); // Reader Settings HasHeaders = hasHeaders; HasMixedData = hasMixedData; switch (extension) { case ".xls": Version = "Excel 8.0"; break; // Excel 95-2003 case ".xlsx": Version = "Excel 12.0"; break; // Excel 2007+ default: throw new ArgumentException("File type could not be determined by file extension.", "path"); } if (IntPtr.Size == 4 && extension == ".xls") Provider = "Microsoft.Jet.OLEDB.4.0"; // for x86/95-2003 else Provider = "Microsoft.ACE.OLEDB.12.0"; // for x64/95-2007+ var strBuilder = new DbConnectionStringBuilder(); strBuilder.Add("Provider", Provider); strBuilder.Add("Data Source", tempFileName); strBuilder.Add("Extended Properties", Version + ";" + "HDR=" + (HasHeaders ? "Yes" : "No") + ';' + "Imex=" + (HasMixedData ? "2" : "0") + ';'); strConnection = strBuilder.ToString(); }
static void Main() { DbConnectionStringBuilder dcsBuilder = new DbConnectionStringBuilder(); dcsBuilder.Add("User ID", "wjzgis"); dcsBuilder.Add("Password", "wjzgis"); dcsBuilder.Add("Service Name", "sunz"); dcsBuilder.Add("Host", "172.16.1.9"); dcsBuilder.Add("Integrated Security", false); string licPath = Application.StartupPath + "\\DDTek.lic"; //dcsBuilder.Add("License Path", licPath); //若路径中存在空格,则会在路径名称前加上"\"" string conStr = dcsBuilder.ConnectionString; conStr = conStr.Replace("\"", ""); Configuration config = new Configuration(); config.AddDirectory(new System.IO.DirectoryInfo(System.IO.Path.Combine(Application.StartupPath, "DataMapping"))); config.Properties["connection.connection_string"] = conStr; NHibernate.ISessionFactory sFactory = config.BuildSessionFactory(); NHibernate.ISession session = sFactory.OpenSession(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
private void CreateConnectionFromParameters() { DbConnectionStringBuilder builder = _factory.CreateConnectionStringBuilder(); try { // most builders should translate these generic keywords // to provider-specific native keywords. if (!String.IsNullOrEmpty(this.UserName)) { builder.Add("User", this.UserName); } if (!String.IsNullOrEmpty(this.Password)) { builder.Add("Password", this.Password); } if (!String.IsNullOrEmpty(this.Server)) { builder.Add("Server", this.Server); } if (!String.IsNullOrEmpty(this.Database)) { builder.Add("Database", this.Database); } } catch (ArgumentException ex) { // invalid keyword(s) throw new ArgumentException(GetValidKeywords(builder), ex); } _connection = _factory.CreateConnection(); _connection.ConnectionString = builder.ConnectionString; }
public DbConnectionStringBuilder GetConnectionStringBuilder() { DbConnectionStringBuilder connectionStringBuilder = OleDbFactory.Instance.CreateConnectionStringBuilder(); connectionStringBuilder.Add("Data Source", DataSource); connectionStringBuilder.Add("Provider", Provider); return(connectionStringBuilder); }
public Task SaveCredentialsAsync(string teamId, CredentialsModel value) { var secret = new DbConnectionStringBuilder(); secret.Add("username", value.Username); secret.Add("password", value.Password); secret.Add("baseAddress", value.BaseAddress); return(SaveSecretAsync(teamId, Providers.Jda, secret.ConnectionString)); }
public Task SaveTokenAsync(string teamId, TokenModel value) { var secret = new DbConnectionStringBuilder(); secret.Add("accessToken", value.AccessToken); secret.Add("refreshToken", value.RefreshToken); secret.Add("expiresDate", value.ExpiresDate); return(SaveSecretAsync(teamId, Providers.Graph, secret.ConnectionString)); }
static void extractTablesAsClasses(CodeGenArgs args2) { string connStr = null, appName = Assembly.GetEntryAssembly().GetName().Name, providerClass; DbProviderFactory factory = args2.providerFactory; DbConnectionStringBuilder sb = null; bool isSqlclient = false; providerClass = factory.GetType().FullName; if (string.Compare(providerClass, "System.Data.SqlClient.SqlClientFactory", true) == 0) { sb = args2.providerFactory.CreateConnectionStringBuilder(); sb.Add("Application Name", appName); sb.Add("Data Source", args2.server); sb.Add("Initial Catalog", args2.database); if (!string.IsNullOrEmpty(args2.userName) && !string.IsNullOrEmpty(args2.password)) { //sb.use System.Data.SqlClient.SqlConnectionStringBuilder sb2; sb2 = sb as System.Data.SqlClient.SqlConnectionStringBuilder; sb2.UserID = args2.userName; sb2.Password = args2.password; } else { sb.Add("Integrated Security", true); } isSqlclient = false; } else { Debug.Print("user/pass here?"); } if (sb != null) { connStr = sb.ConnectionString; Trace.WriteLine("ConnectionString is " + connStr); try { using (DbConnection conn = factory.CreateConnection()) { conn.ConnectionString = connStr; if (isSqlclient) { ((System.Data.SqlClient.SqlConnection)conn).InfoMessage += infoMessageHandler; } ; conn.Open(); generateCodeFromTables(conn, args2); conn.Close(); } } catch (Exception ex) { Trace.WriteLine(ex.Message); //throw new ApplicationException("another", ex); throw; } finally { } } }
/// <summary> /// Мутод - открытия базы данных /// </summary> public void OpenSimplePlayerBD() { DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); builder.Add(@"Data Source", System.Windows.Forms.Application.StartupPath + "\\SimplePlayer.db"); builder.Add(@"Version", 3); BD = new SQLiteConnection(builder.ConnectionString); //Console.Write(builder.ConnectionString); BD.Open(); }
//[ConnectionStringORA]Oracle接続用ConnectionString(ODP/ADO共通) private static string ConnectionStringORA(DbProviderFactory factory) { DbConnectionStringBuilder csb = factory.CreateConnectionStringBuilder(); csb.Add("Data Source", "xxx.xxx.xxx.xxx:9999/SID"); csb.Add("User ID", "USERID"); csb.Add("Password", "PASSWORD"); return(csb.ConnectionString); }
/// <summary> /// "UserName=;Role=;Password=;PasswordHash=" /// </summary> /// <returns></returns> public override string ToString() { var builder = new DbConnectionStringBuilder(); builder.Add("UserName", this.UserName ?? ""); //builder.Add("Role", this.Role ?? ""); builder.Add("Password", this.Password ?? ""); builder.Add("PasswordHash", this.PasswordHash ?? ""); return(builder.ConnectionString); }
private string GetConnectionString(string fileOrServerOrConnectionString) { if (fileOrServerOrConnectionString.IndexOf('=') >= 0) { return(fileOrServerOrConnectionString); } DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); if (fileOrServerOrConnectionString.EndsWith(".mdf", StringComparison.OrdinalIgnoreCase)) { builder.Add("AttachDBFileName", fileOrServerOrConnectionString); builder.Add("Server", @"localhost\sqlexpress"); builder.Add("Integrated Security", "SSPI"); builder.Add("User Instance", "true"); builder.Add("MultipleActiveResultSets", "true"); } else if (fileOrServerOrConnectionString.EndsWith(".sdf", StringComparison.OrdinalIgnoreCase)) { builder.Add("Data Source", fileOrServerOrConnectionString); } else { builder.Add("Server", fileOrServerOrConnectionString); builder.Add("Database", services.Model.DatabaseName); builder.Add("Integrated Security", "SSPI"); } return(builder.ToString()); }
static void InitConnection() { DbConnectionStringBuilder dbsb = new DbConnectionStringBuilder(); dbsb.Add("Server", "localhost"); dbsb.Add("Database", "istoredb"); dbsb.Add("User Id", "root"); dbsb.Add("Password", "admin"); connectionString = dbsb.ConnectionString; }
public static string MakeConnectionString(string server_IP, string loginName, string password, string dataBase) { DbConnectionStringBuilder con = new DbConnectionStringBuilder(); con.Add("Data Source", server_IP); con.Add("Initial Catalog", dataBase); con.Add("uid", loginName); con.Add("pwd", password); return(con.ConnectionString); }
private static string GetConnectionString() { var sb = new DbConnectionStringBuilder(); sb.Add("Data Source", @"(localdb)\MSSQLLocalDB"); sb.Add("Initial Catalog", "Hotel"); //database name sb.Add("Integrated Security", "True"); //enable windows authentication var connection = sb.ConnectionString; return(connection); }
/// <summary> /// Creates a new instance /// </summary> public OleDb(string Provider, string FilePath, string Password) { DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); builder.Add("Provider", Provider); builder.Add("Data Source", FilePath); if (Password != null) { builder.Add("Database Password", Password); } ConnectionString = builder.ConnectionString; }
public async Task <string> GetConnectionString() { if (UseCredentialChain) { var credential = new DefaultAzureCredential(); var accessToken = await credential.GetTokenAsync(new TokenRequestContext(new[] { "https://ossrdbms-aad.database.windows.net" })); stringBuilder.Add("password", accessToken.Token); stringBuilder.Add("sslmode", "Require"); } return(stringBuilder.ConnectionString); }
public override void ActivateOptions() { base.ActivateOptions(); DbConnectionStringBuilder sb = new DbConnectionStringBuilder(); sb.Add("Server", Server); sb.Add("Database", Database); sb.Add("User Id", UserId); sb.Add("Password", Password); ConnectionString = sb.ConnectionString; }
DbConnection Connect(string path) { var builder = new DbConnectionStringBuilder(); builder.Add("Provider", "Microsoft.Jet.OLEDB.4.0"); path = System.IO.Path.GetDirectoryName(path); builder.Add("Data Source", path); builder.Add("Extended Properties", "dBASE III"); var conn = new System.Data.OleDb.OleDbConnection(builder.ConnectionString); conn.Open(); return(conn); }
private static string GenerateConnectionString(string edsSqlSchemaVersion, string connectionString) { string value = Guid.NewGuid().ToString(); DbConnectionStringBuilder dbConnectionStringBuilder = new DbConnectionStringBuilder(); dbConnectionStringBuilder.ConnectionString = connectionString; object obj; if (dbConnectionStringBuilder.TryGetValue("Site", out obj)) { dbConnectionStringBuilder.Remove("Site"); } SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(dbConnectionStringBuilder.ConnectionString); object obj2; if (!sqlConnectionStringBuilder.TryGetValue("Password", out obj2)) { throw new ArgumentException("The connection string must contain a password."); } string password; if (!ManageEdsConnectionStrings.DkmEncryptString(obj2.ToString(), out password)) { throw new ApplicationException("Unable to encrypt password"); } sqlConnectionStringBuilder.Password = password; object obj3; if (!sqlConnectionStringBuilder.TryGetValue("User ID", out obj3) || string.IsNullOrEmpty(obj3.ToString())) { throw new ArgumentException("The connection string must contains a User ID"); } if (!sqlConnectionStringBuilder.TryGetValue("Initial Catalog", out obj3) || string.IsNullOrEmpty(obj3.ToString())) { throw new ArgumentException("The connection string must contains an Initial Catalog"); } if (!sqlConnectionStringBuilder.TryGetValue("Data Source", out obj3) || string.IsNullOrEmpty(obj3.ToString())) { throw new ArgumentException("The connection string must contains a Data Source"); } DbConnectionStringBuilder dbConnectionStringBuilder2 = new DbConnectionStringBuilder(); dbConnectionStringBuilder2.ConnectionString = sqlConnectionStringBuilder.ConnectionString; if (!string.IsNullOrEmpty((string)obj)) { dbConnectionStringBuilder2.Add("Site", obj); } dbConnectionStringBuilder2.Add("Guid", value); dbConnectionStringBuilder2.Add("EdsSqlSchemaVersion", edsSqlSchemaVersion); return(dbConnectionStringBuilder2.ToString()); }
public static DbConnection GetAccessOleConnection(string dbPath, string dbPassword) { DbConnection connection = GetConnection("System.Data.OleDb"); DbConnectionStringBuilder dbcb = ConnectionStringBuilder("System.Data.OleDb"); dbcb.Add("Provider", "Microsoft.Jet.OLEDB.4.0"); dbcb.Add("Data Source", dbPath); if (!String.IsNullOrEmpty(dbPassword)) { dbcb.Add("Jet OLEDB:Database Password", dbPassword); } connection.ConnectionString = dbcb.ConnectionString; return(connection); }
public void doTests() { DbConnection conn = createConnection(); if (_factory is SqlClientFactory) { DbConnectionStringBuilder dcsb; dcsb = new DbConnectionStringBuilder(); dcsb.Add("User ID", "operator"); dcsb.Add("Password", "operator"); dcsb.Add("Application Name", Assembly.GetEntryAssembly().GetName().Name); dcsb.Add("Workstation ID", Environment.MachineName); dcsb.Add("Data Source", "colt-sql"); dcsb.Add("Initial Catalog", "checkweigh_data_dev"); dcsb.Add("Persist Security Info", true); dcsb.Add("Integrated Security", true); conn.ConnectionString = dcsb.ConnectionString; } if (_factory.CanCreateDataSourceEnumerator) { findDataSources(_factory); } DbCommandSelect(conn); ExecuteDbCommand(conn); CreateDataAdapter(_factory, conn.ConnectionString); CreateDataAdapter2(_factory, conn.ConnectionString); }
private EmpressConnection getCSConnection() { DbConnectionStringBuilder csb = new DbConnectionStringBuilder(); csb.ConnectionString = "Server=coral"; csb.Add("database", "/tmp/BankDb"); csb.Add("User", "dli"); csb.Add("Port", 6681); EmpressConnection localConnection = new EmpressConnection(); localConnection.ConnectionString = csb.ToString(); return(localConnection); }
public void CreateFactory_creates_a_ConnectionFactory_from_connectionString(ConnectionStringConnectionFactoryProvider sut, IConfigurationSection section, string hostname, string username, string password, string virtualHost) { var connectionStringBuilder = new DbConnectionStringBuilder(); connectionStringBuilder.Add("HostName", hostname); connectionStringBuilder.Add("Username", username); connectionStringBuilder.Add("Password", password); connectionStringBuilder.Add("VirtualHost", virtualHost); Mock.Get(section).SetupGet(p => p.Value).Returns(connectionStringBuilder.ConnectionString); var factory = sut.CreateFactory(section) as ConnectionFactory; Assert.That(factory, Is.Not.Null); }
public void Add([NotNull] string keyword, [NotNull] string newValue) { Assert.ArgumentNotNullOrEmpty(keyword, nameof(keyword)); Assert.ArgumentNotNullOrEmpty(newValue, nameof(newValue)); _builder.Add(keyword, newValue); }
public DbConnectionStringBuilder GetConnectionStringBuilder() { //Data Source=chumsql2;User ID=mysql;Password=******;Allow Zero Datetime=Yes;Allow User Variables=true;Persist Security Info=true;Default Command Timeout=3600 DbConnectionStringBuilder connectionStringBuilder = MySqlClientFactory.Instance.CreateConnectionStringBuilder(); connectionStringBuilder.Add("Data Source", ServerName); connectionStringBuilder.Add("Database", DatabaseName); connectionStringBuilder.Add("User ID", Credentials.UserId); connectionStringBuilder.Add("Password", Credentials.Password); if (Port > 0) { connectionStringBuilder.Add("Port", Port.ToString()); } return(connectionStringBuilder); }