本文整理汇总了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);
}
示例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);
}
}
}
示例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;
}
示例4: CreateConnection
public static NpgsqlConnection CreateConnection()
{
NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder(GetConnectionString());
csb.Enlist = false;
var connection = new NpgsqlConnection(csb.ToString());
connection.Open();
return connection;
}
示例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);
}
示例6: ForceTestDB
public string ForceTestDB(string connectionString)
{
var cb = new NpgsqlConnectionStringBuilder(connectionString);
if (!cb.Database.EndsWith("_test"))
{
cb.Database += "_test";
}
return cb.ToString();
}
示例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}\"");
}
示例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);
}
示例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();
}
示例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();
}
示例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;
}
}
示例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;
}
});
}
示例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;
}
}
示例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();
}
示例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();
}