本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnectionStringBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnectionStringBuilder.Add方法的具体用法?C# MySqlConnectionStringBuilder.Add怎么用?C# MySqlConnectionStringBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlConnectionStringBuilder
的用法示例。
在下文中一共展示了MySqlConnectionStringBuilder.Add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteBoatSQL
public static void DeleteBoatSQL(string sqlQuery)
{
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
connBuilder.Add("Database", "boatclub");
connBuilder.Add("Data Source", "127.0.0.1");
connBuilder.Add("User Id", "root");
connBuilder.Add("Password", "");
MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);
MySqlCommand cmd = connection.CreateCommand();
connection.Open();
cmd.CommandText = sqlQuery;
cmd.CommandType = CommandType.Text;
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0} {1} {2}",
reader.GetInt32(0), reader.GetString(1), reader.GetString(2))
);
}
reader.Close();
}
示例2: TestBtn_Click
private void TestBtn_Click(object sender, EventArgs e)
{
// Disable console
this.Enabled = false;
// Build Connection String
DbConnectionStringBuilder Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Hostname.Text);
Builder.Add("Port", (int)Port.Value);
Builder.Add("User ID", Username.Text);
Builder.Add("Password", Password.Text);
Builder.Add("Database", DBName.Text);
// Attempt to connect, reporting any and all errors
try
{
MySqlConnection Connection = new MySqlConnection(Builder.ConnectionString);
Connection.Open();
Connection.Close();
}
catch(Exception E)
{
this.Enabled = true;
MessageBox.Show(E.Message, "Connection Error");
return;
}
MessageBox.Show("Connection Successful!", "Success");
this.Enabled = true;
}
示例3: DatabaseDriver
public DatabaseDriver()
{
this.DatabaseEngine = Config.GetDatabaseEngine();
DbConnectionStringBuilder Builder;
if (this.DatabaseEngine == DatabaseEngine.Sqlite)
{
Builder = new SQLiteConnectionStringBuilder();
string FullPath = Path.Combine(Utils.AssemblyPath, Config.GetType<string>("Database", "Database") + ".sqlite3");
IsNewDatabase = !File.Exists(FullPath) || new FileInfo(FullPath).Length == 0;
Builder.Add("Data Source", FullPath);
Connection = new SQLiteConnection(Builder.ConnectionString);
}
else if (this.DatabaseEngine == DatabaseEngine.Mysql)
{
Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Config.GetType<string>("Database", "Hostname"));
Builder.Add("Port", Config.GetType<int>("Database", "Port"));
Builder.Add("User ID", Config.GetType<string>("Database", "Username"));
Builder.Add("Password", Config.GetType<string>("Database", "Password"));
Builder.Add("Database", Config.GetType<string>("Database", "Database"));
Connection = new MySqlConnection(Builder.ConnectionString);
}
else
{
throw new Exception("Invalid Database type.");
}
}
示例4: GetMySqlConn
/// <summary>
///
/// </summary>
/// <param name="connStr">���ܹ��������ַ���</param>
/// <returns></returns>
/// <exception cref="System.NullReferenceException"></exception>
/// <exception cref="System.Execption"></exception>
public static MySqlConnection GetMySqlConn(string connStr)
{
if(string.IsNullOrEmpty(connStr))
{
throw new System.NullReferenceException("�����ֲ���Ϊ��");
}
string tmp = PswdHelper.DecryptString(connStr);
string[] ss = tmp.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if(ss.Length!=5)
{
throw new Exception("�����ָ�ʽ����");
}
MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();
connBuilder.Add("User Id", ss[0]);
connBuilder.Add("Password", ss[1]);
connBuilder.Add("Data Source", ss[2]);
connBuilder.Add("Database", ss[3]);
connBuilder.Add("Charset", ss[4]);
MySqlConnection connection =
new MySqlConnection(connBuilder.ConnectionString);
return connection;
}
示例5: DatabaseDriver
/// <summary>
/// Constructor
/// </summary>
/// <param name="Engine">The string name, from the GetDatabaseEngine() method</param>
/// <param name="Host">The Database server IP Address</param>
/// <param name="Port">The Database server Port Number</param>
/// <param name="DatabaseName">The name of the database</param>
/// <param name="User">A username, with database privliages</param>
/// <param name="Pass">The password to the User</param>
public DatabaseDriver(string Engine, string Host, int Port, string DatabaseName, string User, string Pass)
{
// Set class variables, and create a new connection builder
this.DatabaseEngine = GetDatabaseEngine(Engine);
DbConnectionStringBuilder Builder;
if (this.DatabaseEngine == DatabaseEngine.Sqlite)
{
string FullPath = Path.Combine(MainForm.Root, DatabaseName + ".sqlite3");
IsNewDatabase = !File.Exists(FullPath) || new FileInfo(FullPath).Length == 0;
Builder = new SQLiteConnectionStringBuilder();
Builder.Add("Data Source", FullPath);
Connection = new SQLiteConnection(Builder.ConnectionString);
}
else if (this.DatabaseEngine == DatabaseEngine.Mysql)
{
IsNewDatabase = false;
Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Host);
Builder.Add("Port", Port);
Builder.Add("User ID", User);
Builder.Add("Password", Pass);
Builder.Add("Database", DatabaseName);
Connection = new MySqlConnection(Builder.ConnectionString);
}
else
{
throw new Exception("Invalid Database type.");
}
}
示例6: 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;
}
示例7: 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);
}
示例8: database
static database()
{
conn_str = new MySqlConnectionStringBuilder();
conn_str.Add("Database", "ubit");
conn_str.Add("Data Source", "localhost");
conn_str.Add("User ID", "root");
conn_str.Add("Password", "");
conn = new MySqlConnection(conn_str.ConnectionString);
try
{
conn.Open();
}
catch (MySqlException)
{
MessageBox.Show("Unable to connect to database");
}
}
示例9: DatabaseDriver
/// <summary>
/// Constructor
/// </summary>
/// <param name="Engine">The string name, for the GetDatabaseEngine() method</param>
/// <param name="Host">The Database server IP Address</param>
/// <param name="Port">The Database server Port Number</param>
/// <param name="DatabaseName">The name of the database</param>
/// <param name="User">A username, with database privliages</param>
/// <param name="Pass">The password to the User</param>
public DatabaseDriver(string Engine, string Host, int Port, string DatabaseName, string User, string Pass)
{
// Set class variables, and create a new connection builder
this.DatabaseEngine = GetDatabaseEngine(Engine);
DbConnectionStringBuilder Builder;
// Establish the connection
if (this.DatabaseEngine == DatabaseEngine.Sqlite)
{
// Create the connection
Builder = new SQLiteConnectionStringBuilder();
Builder.Add("Data Source", Path.Combine(Program.RootPath, DatabaseName + ".sqlite3"));
Connection = new SQLiteConnection(Builder.ConnectionString);
}
else if (this.DatabaseEngine == DatabaseEngine.Mysql)
{
// Create the connection
Builder = new MySqlConnectionStringBuilder();
Builder.Add("Server", Host);
Builder.Add("Port", Port);
Builder.Add("User ID", User);
Builder.Add("Password", Pass);
Builder.Add("Database", DatabaseName);
Builder.Add("Convert Zero Datetime", "true");
Connection = new MySqlConnection(Builder.ConnectionString);
}
else
{
throw new Exception("Invalid Database type.");
}
}
示例10: Conectar
public static bool Conectar()
{
bool resultado;
cadenaConexion = new MySqlConnectionStringBuilder();
cadenaConexion.Add("Server", "localhost");
cadenaConexion.Add("Database", "paquetes");
cadenaConexion.Add("Uid", "root");
cadenaConexion.Add("Pwd", "1234");
conexion = new MySqlConnection(cadenaConexion.ToString());
try {
conexion.Open();
resultado = true;
} catch (MySqlException me) {
resultado = false;
throw new Exception(me.Message);
}
return resultado;
}
示例11: Connect
public MySqlConnection Connect()
{
MySqlConnectionStringBuilder connBuilder =
new MySqlConnectionStringBuilder();
connBuilder.Add("Database", "perspectives");
connBuilder.Add("Network Address", "46.137.157.43");
connBuilder.Add("User Id", "group8db");
connBuilder.Add("Port", "4088");
connBuilder.Add("Password", "group8db");
connection =
new MySqlConnection(connBuilder.ConnectionString);
//MySqlCommand cmd = connection.CreateCommand();
connection.Open();
return connection;
// Here goes the code needed to perform operations on the
// database such as querying or inserting rows into a table
}