本文整理汇总了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();
}
示例2: Update
public Update(NpgsqlConnectionStringBuilder connectionInfo)
{
connectionInfo.PreloadReader = true;
_dbName = connectionInfo.Database;
_conn = new NpgsqlConnection(connectionInfo.ConnectionString);
_conn.Open();
}
示例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);
}
}
示例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));
}
}
示例5: ViewModelConnectPgSql
public ViewModelConnectPgSql()
{
_connStrBuilder = new NpgsqlConnectionStringBuilder();
_connStrBuilder.Host = "localhost";
_connStrBuilder.Port = 5432;
_connStrBuilder.SslMode = Npgsql.SslMode.Prefer;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例10: SetUpFixture
public override void SetUpFixture()
{
PostgreSQLInsightDbProvider.RegisterProvider();
_connectionStringBuilder = new NpgsqlConnectionStringBuilder();
_connectionStringBuilder.ConnectionString = "Host = testserver; User Id = postgres; Password = Password1";
_connection = _connectionStringBuilder.Open();
}
示例11: CreateConnection
public static NpgsqlConnection CreateConnection()
{
NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder(GetConnectionString());
csb.Enlist = false;
var connection = new NpgsqlConnection(csb.ToString());
connection.Open();
return connection;
}
示例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);
}
示例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}\"");
}
示例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();
}
示例15: ForceTestDB
public string ForceTestDB(string connectionString)
{
var cb = new NpgsqlConnectionStringBuilder(connectionString);
if (!cb.Database.EndsWith("_test"))
{
cb.Database += "_test";
}
return cb.ToString();
}