當前位置: 首頁>>代碼示例>>C#>>正文


C# NpgsqlConnectionStringBuilder.ToString方法代碼示例

本文整理匯總了C#中Npgsql.NpgsqlConnectionStringBuilder.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# NpgsqlConnectionStringBuilder.ToString方法的具體用法?C# NpgsqlConnectionStringBuilder.ToString怎麽用?C# NpgsqlConnectionStringBuilder.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Npgsql.NpgsqlConnectionStringBuilder的用法示例。


在下文中一共展示了NpgsqlConnectionStringBuilder.ToString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PostgresSqlDatabaseContext

		protected PostgresSqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, PostgresSqlDatabaseContextInfo contextInfo)
			: base(model, sqlDialect, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
		{
			this.SupportsPreparedTransactions = contextInfo.EnablePreparedTransactions;

			this.Host = contextInfo.ServerName;
			this.UserId = contextInfo.UserId;
			this.Password = contextInfo.Password;
			this.Port = contextInfo.Port;
			
			var connectionStringBuilder = new NpgsqlConnectionStringBuilder
			{
				Host = contextInfo.ServerName,
				Username = contextInfo.UserId,
				Password = contextInfo.Password,
				Port = contextInfo.Port,
				Pooling = contextInfo.Pooling,
				Enlist = false,
				MinPoolSize = contextInfo.MinPoolSize,
				MaxPoolSize = contextInfo.MaxPoolSize,
				KeepAlive = contextInfo.KeepAlive,
				ConnectionIdleLifetime = contextInfo.ConnectionIdleLifetime,
				ConvertInfinityDateTime = contextInfo.ConvertInfinityDateTime
			};

			if (contextInfo.Timeout != null)
			{
				connectionStringBuilder.Timeout = contextInfo.Timeout.Value;
			}

			if (contextInfo.ConnectionTimeout.HasValue)
			{
				connectionStringBuilder.Timeout = contextInfo.ConnectionTimeout.Value;
			}
			
			if (contextInfo.ConnectionCommandTimeout.HasValue)
			{
				connectionStringBuilder.CommandTimeout = contextInfo.ConnectionCommandTimeout.Value;
			}

			connectionStringBuilder.Database = contextInfo.DatabaseName;

			this.ConnectionString = connectionStringBuilder.ToString();

			connectionStringBuilder.Database = "postgres";

			this.ServerConnectionString = connectionStringBuilder.ToString();

			this.SchemaManager = new PostgresSqlDatabaseSchemaManager(this);
		}
開發者ID:tumtumtum,項目名稱:Shaolinq,代碼行數:50,代碼來源:PostgresSqlDatabaseContext.cs

示例2: 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

示例3: 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

示例4: 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

示例5: Bug1011001

        public void Bug1011001()
        {
            //[#1011001] Bug in NpgsqlConnectionStringBuilder affects on cache and connection pool

            var csb1 = new NpgsqlConnectionStringBuilder(@"Server=server;Port=5432;User Id=user;Password=passwor;Database=database;");
            var cs1 = csb1.ToString();
            var csb2 = new NpgsqlConnectionStringBuilder(cs1);
            var cs2 = csb2.ToString();
            Assert.IsTrue(cs1 == cs2);
        }
開發者ID:Rungee,項目名稱:Npgsql2,代碼行數:10,代碼來源:ConnectionTests.cs

示例6: 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

示例7: 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

示例8: PostgresSqlDatabaseContext

        protected PostgresSqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, PostgresSqlDatabaseContextInfo contextInfo)
            : base(model, sqlDialect, sqlDataTypeProvider, sqlQueryFormatterManager, contextInfo.DatabaseName, contextInfo)
        {
            this.Host = contextInfo.ServerName;
            this.UserId = contextInfo.UserId;
            this.Password = contextInfo.Password;
            this.Port = contextInfo.Port;

            var connectionStringBuilder = new NpgsqlConnectionStringBuilder
            {
                Host = contextInfo.ServerName,
                Username = contextInfo.UserId,
                Password = contextInfo.Password,
                Port = contextInfo.Port,
                Pooling = contextInfo.Pooling,
                Enlist = false,
                BackendTimeouts = contextInfo.BackendTimeouts,
                MinPoolSize = contextInfo.MinPoolSize,
                MaxPoolSize = contextInfo.MaxPoolSize
            };

            if (contextInfo.ConnectionTimeout.HasValue)
            {
                connectionStringBuilder.Timeout = contextInfo.ConnectionTimeout.Value;
            }

            if (contextInfo.ConnectionCommandTimeout.HasValue)
            {
                connectionStringBuilder.CommandTimeout = contextInfo.ConnectionCommandTimeout.Value;
            }

            connectionStringBuilder.Database = contextInfo.DatabaseName;

            this.ConnectionString = connectionStringBuilder.ToString();

            connectionStringBuilder.Database = "postgres";

            this.ServerConnectionString = connectionStringBuilder.ToString();

            this.SchemaManager = new PostgresSqlDatabaseSchemaManager(this);
        }
開發者ID:ciker,項目名稱:Shaolinq,代碼行數:41,代碼來源:PostgresSqlDatabaseContext.cs

示例9: Main

        static void Main(string[] args)
        {
            var b = new NpgsqlConnectionStringBuilder() { Host = "milkyway", Port = 5433, Username = "neocortex", Password = "masterboot", Database = "db" };

            using (DbConnection conn = new NpgsqlConnection(b.ToString()))
            {
                conn.Open();

                var tables = new List<string>();
                var all = conn.GetSchema("Tables");
                foreach (DataRow r in all.Rows)
                {
                    //table_catalog //table_schema //table_name //table_type
                    var schema = r["table_schema"];
                    var table = r["table_name"];
                    var type = r["table_type"];

                    if ("kernel".Equals(schema.ToString()))
                        tables.Add(table.ToString());
                }

                foreach (var table in tables)
                {
                    Console.WriteLine("Table: " + table);

                    var tableSchema = conn.GetSchema("Columns", new string[] { null, null, table });
                    foreach (DataRow row in tableSchema.Rows)
                    {
                        Console.WriteLine("Column = {0}. Type = {1}. Default = {2}. Nullable = {3}. Text lenght = {4}. Numeric precision = {5}.",
                            row["column_name"],
                            row["data_type"],
                            row["column_default"],
                            row["is_nullable"],
                            row["character_maximum_length"],
                            row["numeric_precision"]);
                    }
                }

                /*var cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = @"SELECT * FROM kernel.users;";

                using (var reader = cmd.ExecuteReader())
                    while (reader.Read())
                        Console.WriteLine(string.Format("id = {0}, user = {1};", reader.GetString(0), reader.GetString(1)));
                */

            }

            Console.ReadKey();
        }
開發者ID:elpy,項目名稱:DynORM,代碼行數:51,代碼來源:Program.cs

示例10: MainForm

        public MainForm()
        {
            InitializeComponent();
            RecordsProgressBar.Maximum = RecordsMax;
            _count = 0;
            _close = false;
            _threadsCounter = 0;

            DbConnectionStringBuilder connectionStringBuilder = new NpgsqlConnectionStringBuilder();
            connectionStringBuilder.Add("Server", "localhost");
            connectionStringBuilder.Add("Port", "5432");
            connectionStringBuilder.Add("User Id", "postgres");
            connectionStringBuilder.Add("Password", "1");
            connectionStringBuilder.Add("Database", "project");
            _dbConnectionString = connectionStringBuilder.ToString();
        }
開發者ID:kazami-yuuji,項目名稱:dbParser,代碼行數:16,代碼來源:MainForm.cs

示例11: DBService

 public DBService(ConnectionVO connVO,string HostURL)
 {
     try
     {
         NpgsqlConnectionStringBuilder nsb = new NpgsqlConnectionStringBuilder();
         nsb.Host = HostURL;
         nsb.Port = 5432;
         nsb.SSL = false;
         nsb.IntegratedSecurity = false;
         nsb.UserName = "postgres";
         nsb.Database = connVO.DataBaseName;
         nsb.Password = connVO.DBPassword;
         NpgConn = new NpgsqlConnection(nsb.ToString());
         NpgConn.Open();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
開發者ID:hesed7,項目名稱:hitpan,代碼行數:20,代碼來源:DBService.cs

示例12: RequiresPostgresFactAttribute

		static RequiresPostgresFactAttribute()
		{
			IsPostgresAvailable = new Lazy<bool>(() =>
			{
				try
				{
					var builder = new NpgsqlConnectionStringBuilder(PostgresFixture.ConnectionString);
					builder.Timeout = 1000;

					using (var connection = new NpgsqlConnection(builder.ToString()))
					{
						connection.Open();
						return connection.State == ConnectionState.Open;
					}
				}
				catch (Exception)
				{
					return false;
				}
			});
		}
開發者ID:Pondidum,項目名稱:Ledger.Stores.Postgres,代碼行數:21,代碼來源:RequiresPostgresFactAttribute.cs

示例13: PostgresSQLDBServicecs

 public PostgresSQLDBServicecs(ConnectionVO connVO)
 {
     try
     {
         this.myConnVO = connVO;
         NpgsqlConnectionStringBuilder nsb = new NpgsqlConnectionStringBuilder();
         nsb.Host = connVO.HostURL;
         nsb.Port = 5432;
         nsb.SSL = false;
         nsb.IntegratedSecurity = false;
         nsb.UserName = connVO.DBID;
         nsb.Database = connVO.DataBaseName;
         nsb.Password = connVO.DBPassword;
         nsb.Pooling = false;
         NpgConn = new NpgsqlConnection(nsb.ToString());
         NpgConn.Open();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
開發者ID:hesed7,項目名稱:hitpan,代碼行數:22,代碼來源:PostgresSQLDBServicecs.cs

示例14: Answer

        /*List<SpaceWar2006.GameSystem.GameServerInfo> infos = new List<SpaceWar2006.GameSystem.GameServerInfo>();

        protected void Answer(NetIncomingMessage msg)
        {
            SpaceWar2006.GameSystem.GameServerInfo info;
            {
                string p = msg.ReadString();
                info = new SpaceWar2006.GameSystem.GameServerInfo(p);
                infos.Add(info);
            }
        }*/
        protected void Page_Load(object sender, EventArgs e)
        {
            /*ServerFinder finder = new ServerFinder(new ServerFinder.AnswerDelegate(Answer), false, true);

            GridView1.AutoGenerateColumns = true;

            for (int i = 0; i < 5; ++i)
            {
                finder.Tick(0.5f);
                Thread.Sleep(500);
            }

            GridView1.DataSource = infos;
            GridView1.DataBind();*/

            NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder ();
            builder.Host = "localhost";
            builder.Password = "";
            builder.Pooling = false;
            builder.UserName = "postgres";
            builder.Database = "game";

            NpgsqlConnection c=new NpgsqlConnection(builder.ToString());
            c.Open();

            NpgsqlCommand cmd = c.CreateCommand ();
            cmd.CommandText = @"SELECT s2.id,s2.name,s2.host,s2.port,i2.time,i2.map,i2.numplayers,i2.maxplayers FROM
            (SELECT s.id AS id,MAX(i.time) AS maxtime FROM gameserver s
            LEFT JOIN gameinfo i ON s.id=i.gameserver_id
            GROUP BY s.id) AS times
            LEFT JOIN gameserver s2 ON times.id=s2.id
            LEFT JOIN gameinfo i2 ON times.id=i2.gameserver_id AND times.maxtime=i2.time";
            //NpgsqlDataReader r = cmd.ExecuteReader();
            NpgsqlDataAdapter a=new NpgsqlDataAdapter(cmd);
            DataTable dt=new DataTable();
            a.Fill(dt);
            GridView1.DataSource=dt;
            GridView1.DataBind();
        }
開發者ID:cody82,項目名稱:spacewar-arena,代碼行數:50,代碼來源:Default.aspx.cs

示例15: PostgreSQLDatabase

        public PostgreSQLDatabase()
        {
            Name = "Postgre";
            CollectionName = "table1";
            Category = "SQL";
            Description = "PostgreSQL + Npgsql 2.0.13.91 .NET Data Provider";
            Website = "http://www.postgresql.org/";
            Color = System.Drawing.Color.FromArgb(0, 148, 196);

            Requirements = new string[]
            {
                "MySql.Data.dll"
            };

            NpgsqlConnectionStringBuilder cs = new NpgsqlConnectionStringBuilder();
            cs.Host = "localhost";
            cs.Port = 5432;
            cs.UserName = "postgres";
            cs.Password = "123456789";
            cs.CommandTimeout = 0;
            cs.ConnectionLifeTime = 0;
            ConnectionString = cs.ToString();
        }
開發者ID:pavel-gridnev,項目名稱:DatabaseBenchmark,代碼行數:23,代碼來源:PostgreSQLDatabase.cs


注:本文中的Npgsql.NpgsqlConnectionStringBuilder.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。