当前位置: 首页>>代码示例>>C#>>正文


C# Npgsql.NpgsqlConnectionStringBuilder类代码示例

本文整理汇总了C#中Npgsql.NpgsqlConnectionStringBuilder的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnectionStringBuilder类的具体用法?C# NpgsqlConnectionStringBuilder怎么用?C# NpgsqlConnectionStringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NpgsqlConnectionStringBuilder类属于Npgsql命名空间,在下文中一共展示了NpgsqlConnectionStringBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectionStringDialog

 /// <summary>
 /// Default Constructor
 /// </summary>
 public ConnectionStringDialog()
 {
     InitializeComponent();
     this.cmbServerName.Items.Add("<Browse for more>");
     this.cmbServerName.Text = "";
     dbConnectionStringBuilder = new NpgsqlConnectionStringBuilder();
 }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:10,代码来源:ConnectionStringDialog.cs

示例2: Update

 public Update(NpgsqlConnectionStringBuilder connectionInfo)
 {
     connectionInfo.PreloadReader = true;
     _dbName = connectionInfo.Database;
     _conn = new NpgsqlConnection(connectionInfo.ConnectionString);
     _conn.Open();
 }
开发者ID:Bitorchestra,项目名称:DotPgDiff,代码行数:7,代码来源:Update.cs

示例3: BuildStartupPacket

        public static NpgsqlStartupPacket BuildStartupPacket(ProtocolVersion protocol_version, String database_name, String user_name,
                                                             NpgsqlConnectionStringBuilder  settings)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "BuildStartupPacket");

            if (protocol_version == ProtocolVersion.Version2)
            {
                return new NpgsqlStartupPacketV2(database_name,user_name, "", "", "");
            }
            else
            {
                Dictionary<String, String> parameters = new Dictionary<String, String>();

                parameters.Add("DateStyle", "ISO");
                parameters.Add("client_encoding", "UTF8");
                parameters.Add("extra_float_digits", "2");
                parameters.Add("lc_monetary", "C");

                if (!string.IsNullOrEmpty(settings.ApplicationName))
                {
                    parameters.Add("application_name", settings.ApplicationName);
                }

                if (!string.IsNullOrEmpty(settings.SearchPath))
                {
                    parameters.Add("search_path", settings.SearchPath);
                }

                return new NpgsqlStartupPacketV3(database_name,user_name,parameters);
            }
        }
开发者ID:udoliess,项目名称:npgsql,代码行数:31,代码来源:NpgsqlStartupPacket.cs

示例4: NpgsqlStartupPacket

        public NpgsqlStartupPacket(String database_name, String user_name, NpgsqlConnectionStringBuilder  settings)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "BuildStartupPacket");

            Dictionary<String, String> parameters = new Dictionary<String, String>();

            parameters.Add("DateStyle", "ISO");
            parameters.Add("client_encoding", "UTF8");
            parameters.Add("extra_float_digits", "2");

            if (! string.IsNullOrEmpty(settings.ApplicationName))
            {
                parameters.Add("application_name", settings.ApplicationName);
            }

            if (! string.IsNullOrEmpty(settings.SearchPath))
            {
                parameters.Add("search_path", settings.SearchPath);
            }

            //database
            parameterNames.Add(BackendEncoding.UTF8Encoding.GetBytes("database"));
            parameterValues.Add(BackendEncoding.UTF8Encoding.GetBytes(database_name));

            //user
            parameterNames.Add(BackendEncoding.UTF8Encoding.GetBytes("user"));
            parameterValues.Add(BackendEncoding.UTF8Encoding.GetBytes(user_name));

            //parameters
            foreach (KeyValuePair<String, String> param in parameters)
            {
                parameterNames.Add(BackendEncoding.UTF8Encoding.GetBytes(param.Key));
                parameterValues.Add(BackendEncoding.UTF8Encoding.GetBytes(param.Value));
            }
        }
开发者ID:mono,项目名称:linux-packaging-npgsql,代码行数:35,代码来源:NpgsqlStartupPacket.cs

示例5: ViewModelConnectPgSql

 public ViewModelConnectPgSql()
 {
     _connStrBuilder = new NpgsqlConnectionStringBuilder();
     _connStrBuilder.Host = "localhost";
     _connStrBuilder.Port = 5432;
     _connStrBuilder.SslMode = Npgsql.SslMode.Prefer;
 }
开发者ID:HabitatFramework,项目名称:HLUTool,代码行数:7,代码来源:ViewModelConnectPgSql.cs

示例6: Initialize

        public static void Initialize()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["TestDb"].ConnectionString;
            var connectionBuilder = new NpgsqlConnectionStringBuilder(connectionString);

            //connect to postgres database to create a new database
            var databaseName = connectionBuilder.Database;
            connectionBuilder.Database = "postgres";
            connectionString = connectionBuilder.ToString();

            using (var conn = new NpgsqlConnection(connectionString))
            {
                conn.Open();

                bool dbExists;
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.CommandText = string.Format(@"SELECT TRUE FROM pg_database WHERE datname='{0}'", databaseName);
                    cmd.Connection = conn;

                    var result = cmd.ExecuteScalar();
                    dbExists = result != null && Convert.ToBoolean(result);
                }

                if (dbExists)
                {
                    DoClean(conn);
                }
                else
                {
                    DoCreate(conn, databaseName);
                }
            }
        }
开发者ID:MaciekLesiczka,项目名称:akka.net,代码行数:34,代码来源:DbUtils.cs

示例7: Initialize

        public IDocumentStore Initialize(Action<MartenRegistry> register = null)
        {
            var builder = new NpgsqlConnectionStringBuilder(_targetConnectionString);
            var targetDatabaseName = builder.Database;

            using (var connection = new NpgsqlConnection(_masterConnectionString))
            {
                connection.Open();
                var existsCommand = connection.CreateCommand();
                existsCommand.CommandText = "select (count(*) > 0)::boolean as exists from pg_database where datname=:0";
                existsCommand.Parameters.Add(new NpgsqlParameter("0", targetDatabaseName));
                var exists = (bool)existsCommand.ExecuteScalar();
                if (!exists)
                {
                    var createCommand = connection.CreateCommand();
                    createCommand.CommandText = string.Format("CREATE DATABASE \"{0}\"", targetDatabaseName);
                    createCommand.ExecuteNonQuery();
                }
            }
            var store = DocumentStore.For(cfg =>
            {
                cfg.Connection(_targetConnectionString);
                cfg.AutoCreateSchemaObjects = true;
                cfg.Schema.For<Commit>()
                    .Searchable(x => x.StreamId)
                    .Searchable(x => x.StreamVersion);
                if (register != null)
                {
                    register(cfg.Schema);
                }
            });
            return store;
        }
开发者ID:jeffdoolittle,项目名称:Marten.Domain,代码行数:33,代码来源:Initializer.cs

示例8: connectFischFaunaButton_Click

        // Zu Quell- und Zieldatenbank verbinden
        private void connectFischFaunaButton_Click(object sender, EventArgs e)
        {
            DatabaseConnection sourceCon = (DatabaseConnection)sourceDatabaseConnetions.SelectedValue;
            DatabaseConnection targetCon = (DatabaseConnection)targetDatabaseConnetions.SelectedValue;

            NpgsqlConnectionStringBuilder pgConStrBuilder = new NpgsqlConnectionStringBuilder();
            pgConStrBuilder.Host = sourceCon.ServerAddress;
            pgConStrBuilder.UserName = sourceCon.UserName;
            pgConStrBuilder.Password = sourceCon.Password;
            pgConStrBuilder.Database = sourceCon.Database;

            MySqlConnectionStringBuilder mySqlConStrBuilder = new MySqlConnectionStringBuilder();
            mySqlConStrBuilder.Server = targetCon.ServerAddress;
            mySqlConStrBuilder.UserID = targetCon.UserName;
            mySqlConStrBuilder.Password = targetCon.Password;
            mySqlConStrBuilder.Database = targetCon.Database;
            mySqlConStrBuilder.AllowZeroDateTime = true;

            _sourceCon = new NpgsqlConnection(pgConStrBuilder.ToString());
            _targetCon = new MySqlConnection(mySqlConStrBuilder.ToString());

            _mainLogic = new MainLogic(_sourceCon, _targetCon);
            _mainLogic.CheckForImportedFieldInMySql();

            FillImportsCombobox();
            FillImportUsersCombobox();
            FillRecordQualityCombobox();
            FillSourceTypeCombobox();
            FillCountryCombobox();

            PreSelectTestData();

            groupBox2.Enabled = true;
        }
开发者ID:bastoGrande,项目名称:DbMigrate,代码行数:35,代码来源:mainForm.cs

示例9: Main

        static void Main(string[] args)
        {
            var databaseName = args.Length > 0
                ? args[0]
                : null;

            var connectionString = new NpgsqlConnectionStringBuilder
            {
                Host = ConfigurationManager.AppSettings["host"],
                Database = databaseName ?? ConfigurationManager.AppSettings["database"],
                Username = ConfigurationManager.AppSettings["user"],
                Password = ConfigurationManager.AppSettings["password"],

                SslMode = SslMode.Prefer,
                TrustServerCertificate = true
            }
            .ConnectionString;

            var upgradeEngine = DeployChanges.To
                .PostgresqlDatabase(connectionString)
                .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                .LogToConsole()
                .Build();

            var result = upgradeEngine.PerformUpgrade();
            if (!result.Successful)
            {
                Console.ReadLine();
            }
        }
开发者ID:carlos-vicente,项目名称:Playground,代码行数:30,代码来源:Program.cs

示例10: SetUpFixture

		public override void SetUpFixture()
		{
			PostgreSQLInsightDbProvider.RegisterProvider();

			_connectionStringBuilder = new NpgsqlConnectionStringBuilder();
			_connectionStringBuilder.ConnectionString = "Host = testserver; User Id = postgres; Password = Password1";
			_connection = _connectionStringBuilder.Open();
		}
开发者ID:ronnieoverby,项目名称:Insight.Database,代码行数:8,代码来源:PostgreSQLTests.cs

示例11: CreateConnection

        public static NpgsqlConnection CreateConnection()
        {
            NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder(GetConnectionString());
            csb.Enlist = false;
            var connection = new NpgsqlConnection(csb.ToString());
            connection.Open();

            return connection;
        }
开发者ID:andesantis,项目名称:Hangfire.PostgreSql,代码行数:9,代码来源:ConnectionUtils.cs

示例12: Startup

        public override void Startup(NpgsqlConnector context,NpgsqlConnectionStringBuilder settings)
        {
            NpgsqlStartupPacket startupPacket = new NpgsqlStartupPacket(context.Database, context.UserName, settings);

            startupPacket.WriteToStream(context.Stream);
            context.RequireReadyForQuery = false;

            ProcessAndDiscardBackendResponses(context);
        }
开发者ID:baondp,项目名称:Npgsql,代码行数:9,代码来源:NpgsqlConnectedState.cs

示例13: CreateDatabase

      private static void CreateDatabase()
      {
         var cxBuilder = new NpgsqlConnectionStringBuilder(ConnectionString);
         var database = cxBuilder.Database;
         cxBuilder.Database = null;

         var db = new NpgsqlConnection(cxBuilder.ToString());
         db.Execute($"DROP DATABASE IF EXISTS \"{database}\"");
         db.Execute($"CREATE DATABASE \"{database}\"");
      }
开发者ID:henrik-m,项目名称:linqpad-postgresql-driver,代码行数:10,代码来源:DatabaseFixture.cs

示例14: DatabaseWorker

 public DatabaseWorker()
 {
     var connectionParams = new NpgsqlConnectionStringBuilder();
     connectionParams.Host = "127.0.0.1";
     connectionParams.UserName = "bbadmin";
     connectionParams.Password = "qwerty";
     connectionParams.Database = "bbrother";
     _pgConnect = new NpgsqlConnection(connectionParams.ConnectionString);
     _pgConnect.Open();
 }
开发者ID:AndreyRepko,项目名称:BBrother,代码行数:10,代码来源:DatabaseWorker.cs

示例15: ForceTestDB

        public string ForceTestDB(string connectionString)
        {
            var cb = new NpgsqlConnectionStringBuilder(connectionString);
            if (!cb.Database.EndsWith("_test"))
            {
                cb.Database += "_test";
            }

            return cb.ToString();
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:10,代码来源:PostgreSqlResetter.cs


注:本文中的Npgsql.NpgsqlConnectionStringBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。