本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnectionStringBuilder.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnectionStringBuilder.ToString方法的具体用法?C# MySqlConnectionStringBuilder.ToString怎么用?C# MySqlConnectionStringBuilder.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlConnectionStringBuilder
的用法示例。
在下文中一共展示了MySqlConnectionStringBuilder.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public override bool Connect() {
bool opened = true;
if (this.Connection == null || this.Connection.State == ConnectionState.Closed) {
if (this.Connection != null) {
this.Connection.Close();
this.Connection = null;
}
MySqlConnectionStringBuilder connectionBuilder = new MySqlConnectionStringBuilder {
Server = this.Settings.Hostname,
Port = this.Settings.Port != null ? this.Settings.Port.Value : 0,
Database = this.Settings.Database,
UserID = this.Settings.Username,
Password = this.Settings.Password,
UseCompression = true
};
try {
this.Connection = new MySqlConnection(connectionBuilder.ToString());
this.Connection.Open();
if (this.Connection.State != ConnectionState.Open) {
this.Connection.Close();
this.Connection = null;
}
}
catch {
opened = false;
}
}
return opened;
}
示例2: CreateConnection
public DbConnection CreateConnection(string nameOrConnectionString)
{
var connectionBuilder = new MySqlConnectionStringBuilder(_baseConnectionString);
connectionBuilder.Database = nameOrConnectionString;
return new MySqlConnection(connectionBuilder.ToString());
}
示例3: Command
public static void Command(string command)
{
try
{
var connstring = new MySqlConnectionStringBuilder
{
Server = meh.Default.MysqlHost,
UserID = meh.Default.MysqlUsername,
Password = meh.Default.MysqlPassword,
Database = meh.Default.MysqlDatabase
};
var connection = new MySqlConnection(connstring.ToString());
LogWriter.WriteLine(@"opening connection to mysql");
connection.Open();
LogWriter.WriteLine(@"connection successful!");
var sqlcommand = new MySqlCommand(command, connection);
LogWriter.WriteLine(@"Running sql command");
sqlcommand.ExecuteNonQuery();
LogWriter.WriteLine(@"Sql Command finished.");
}
catch (Exception ex)
{
MessageBox.Show(@"An Error occured while importing the file!, log output should have more info.");
LogWriter.WriteLine(ex.Data + ex.StackTrace + ex.Message);
}
}
示例4: CreateDatabaseAsync
public static Task CreateDatabaseAsync(this MySqlDatabase db)
{
return Task.Run(() =>
{
MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder();
connStr.Server = db.Host;
connStr.Port = (uint)db.Port;
connStr.UserID = db.Username;
connStr.Password = db.Password;
string connString = connStr.ToString();
string nonQuery = String.Format("DROP DATABASE IF EXISTS {0}; CREATE DATABASE {0};", db.DatabaseName);
using (MySqlConnection conn = new MySqlConnection(connString))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand(nonQuery, conn))
{
cmd.ExecuteNonQuery();
}
conn.Close();
}
});
}
示例5: DataTable
DataTable dt_dr = new DataTable(); // tek tablo
#endregion Fields
#region Constructors
public Form3(MySqlConnectionStringBuilder _bag)
{
InitializeComponent();
MySqlConnection conn = new MySqlConnection(_bag.ToString());
MySqlCommand cmd_hasta_sel = new MySqlCommand("select h.tc,h.adsoyad,d.doktorad from hasta h inner join doktor d on d.iddoktor=h.iddr;", conn);
da_hasta = new MySqlDataAdapter();
da_hasta.SelectCommand = cmd_hasta_sel;
MySqlCommand cmd_dr_sel = new MySqlCommand("select iddoktor, doktorad from doktor;", conn);
MySqlDataAdapter da_dr = new MySqlDataAdapter();
da_dr.SelectCommand = cmd_dr_sel;
da_dr.Fill(dt_dr); // doktorlarin listesi
da_hasta_ekle = new MySqlDataAdapter(); // hasta eklemek icin
MySqlCommand cmdhasta_sel = new MySqlCommand("select tc, adsoyad, iddr from hasta;", conn);
MySqlCommand cmdhasta_ins = new MySqlCommand("insert into hasta(tc, adsoyad, iddr) values(@tc, @adsoyad, @iddr);", conn);
cmdhasta_ins.Parameters.Add("@tc", MySqlDbType.VarChar, 11, "tc");
cmdhasta_ins.Parameters.Add("@adsoyad", MySqlDbType.VarChar, 45, "adsoyad");
cmdhasta_ins.Parameters.Add("@iddr", MySqlDbType.Int32, 11, "iddr");
da_hasta_ekle.SelectCommand = cmdhasta_sel;
da_hasta_ekle.InsertCommand = cmdhasta_ins;
verigetir();
// doktorlarin listesini comboya
for (int i = 0; i < dt_dr.Rows.Count; i++)
cdoktor.Items.Add(dt_dr.Rows[i].ItemArray[1].ToString());
}
示例6: 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;
}
示例7: MySqlConnection
// Передача параметров подключения фенкции, с последующим назначением свойств.
/// <summary>
/// Метод MySqlConnection. Устанавливает подлючение к БД.
/// </summary>
public static bool MySqlConnection(string user, string passwd, string host, string db, bool test)
{
User = user;
Pass = passwd;
Host = host;
DB = db;
MySqlConnectionStringBuilder mysqlSting = new MySqlConnectionStringBuilder();
mysqlSting.Server = Host;
mysqlSting.Database = DB;
mysqlSting.UserID = User;
mysqlSting.Password = Pass;
mysqlSting.CharacterSet = "utf8";
connection = new MySqlConnection(mysqlSting.ToString());
{
try
{
connection.Open();
connection.Close();
return true;
}
catch { return false; }
}
}
示例8: WizardSelectDatabaseViewModel
public WizardSelectDatabaseViewModel(WizardSelectDatabaseModel model, string host, int port, string username, string password)
{
WizardSelectDatabase = model;
OkCommand = new Command(Ok);
CancelCommand = new Command(CancelCmd);
var connStr = new MySqlConnectionStringBuilder();
connStr.Server = host;
connStr.Port = (uint)port;
connStr.UserID = username;
connStr.Password = password;
using (var connection = new MySqlConnection(connStr.ToString()))
{
connection.Open();
using (var returnVal = new MySqlDataAdapter("SHOW DATABASES", connection))
{
var dataTable = new DataTable();
returnVal.Fill(dataTable);
foreach (DataRow row in dataTable.Rows)
for (int i = 0; i < row.ItemArray.Length; i++)
Databases.Add(row.ItemArray[i].ToString());
}
}
}
示例9: CurrentEnvironment
/// <summary>
/// static constructor to determine the state of the environment and set defaults
/// </summary>
static CurrentEnvironment()
{
// Not on cloud foundry filling in the blanks.
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
{
Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
}
// check to see if DB is bound, if so...what type
// sql server first
if (BoundServices.GetValue("mssql-dev") != null) // sql server
{
DbEngine = DatabaseEngine.SqlServer;
_connectionString = BoundServices["mssql-dev"][0]["credentials"]["connectionString"].ToString();
}
else if (BoundServices.GetValue("p-mysql") != null)
{
DbEngine = DatabaseEngine.MySql;;
MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
csbuilder.Add("server", BoundServices["p-mysql"][0]["credentials"]["hostname"].ToString());
csbuilder.Add("port", BoundServices["p-mysql"][0]["credentials"]["port"].ToString());
csbuilder.Add("uid", BoundServices["p-mysql"][0]["credentials"]["username"].ToString());
csbuilder.Add("pwd", BoundServices["p-mysql"][0]["credentials"]["password"].ToString());
csbuilder.Add("database", BoundServices["p-mysql"][0]["credentials"]["name"].ToString());
_connectionString = csbuilder.ToString();
}
else
DbEngine = DatabaseEngine.None;
}
示例10: buttonConnect_Click
private void buttonConnect_Click(object sender, EventArgs e)
{
bool succesConnection = true;
var builder = new MySqlConnectionStringBuilder();
builder.Server = textBoxAddress.Text.Trim();
builder.UserID = textBoxUsername.Text.Trim();
builder.Password = textBoxPassword.Text.Trim();
builder.Port = Convert.ToUInt16(textBoxPort.Text);
builder.Database = textBoxAuth.Text.Trim();
if (!ConnectDB(builder.ToString()))
{
succesConnection = false;
}
builder.Database = textBoxCharacters.Text.Trim();
if (!ConnectDB(builder.ToString()))
{
succesConnection = false;
}
builder.Database = textBoxWorld.Text.Trim();
if (!ConnectDB(builder.ToString()))
{
succesConnection = false;
}
if (succesConnection)
{
SaveSettings();
Andress = textBoxAddress.Text;
Port = Convert.ToUInt16(textBoxPort.Text);
Username = textBoxUsername.Text;
Password = textBoxPassword.Text;
DatabaseAuth = textBoxAuth.Text;
DatabaseCharacters = textBoxCharacters.Text;
DatabaseWorld = textBoxWorld.Text;
this.Hide();
var mf = new FormMain();
mf.FormClosed += (s, args) => this.Close();
mf.Show();
}
}
示例11: MySqlClassGenerator
/// <summary>
/// Initializes a new instance of the <see cref="MySqlClassGenerator"/> class.
/// </summary>
/// <param name="server">The server.</param>
/// <param name="userID">The user ID.</param>
/// <param name="password">The password.</param>
/// <param name="database">The database.</param>
/// <param name="port">The port.</param>
public MySqlClassGenerator(string server, string userID, string password, string database, uint port = 3306u)
{
var sb = new MySqlConnectionStringBuilder
{ Server = server, UserID = userID, Password = password, Database = database, Port = port };
_conn = new MySqlConnection(sb.ToString());
SetDbConnection(_conn);
}
示例12: GetConnection
public static MySqlConnection GetConnection()
{
var connString = new MySqlConnectionStringBuilder
{
//Connection Settings
};
return new MySqlConnection(connString.ToString());
}
示例13: OpenConnection
public IDbConnection OpenConnection()
{
var mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder(_connectionString)
{
Database = _databaseName
};
var mySqlConnection = new MySqlConnection(mySqlConnectionStringBuilder.ToString());
mySqlConnection.Open();
return mySqlConnection;
}
示例14: ConnectionString
public static string ConnectionString()
{
var cnB = new MySqlConnectionStringBuilder();
cnB["Data Source"] = "198.71.225.52";
cnB["Initial Catalog"] = "ninjatekweb_";
cnB["UID"] = "ninjatekadmin";
cnB["Password"] = "[email protected]";
cnB["Convert Zero Datetime"] = true;
return cnB.ToString();
}
示例15: DB
static DB()
{
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
connBuilder.Add("Database", "Project_JJK");
connBuilder.Add("Data Source", "hellojkw.com");
connBuilder.Add("User Id", "uj7380");
connBuilder.Add("Password", "uj7380");
_connectionString = connBuilder.ToString();
Conn = new MySqlConnection(_connectionString);
}