本文整理匯總了C#中MySql.Data.MySqlClient.MySqlConnection.Ping方法的典型用法代碼示例。如果您正苦於以下問題:C# MySqlConnection.Ping方法的具體用法?C# MySqlConnection.Ping怎麽用?C# MySqlConnection.Ping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MySql.Data.MySqlClient.MySqlConnection
的用法示例。
在下文中一共展示了MySqlConnection.Ping方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: seEjecutoComando
}//End public bool seEjecutoComando()
public bool Conectar()
{
MySqlConnection mConnection = new MySqlConnection(MyConString);
try
{
mConnection.Open();
}
catch (Exception ex)
{
return false;
}
if (mConnection.Ping())
{
//Command = Connection.CreateCommand();
return true;
}//End if (Connection.Ping())
return false;
}//End public void Conectar()
示例2: ConnectionTest
public void ConnectionTest() {
DefaultConnectionString.Should().Not.Be.Empty();
using(var conn = new MySqlConnection(DefaultConnectionString)) {
conn.Open();
conn.Ping().Should().Be.True();
}
}
示例3: DataBase
public DataBase()
{
MySqlConnectionStringBuilder _connectionSB = new MySqlConnectionStringBuilder();
_connectionSB.Server = "localhost";
_connectionSB.UserID = "server";
_connectionSB.Password = "1111";
_connectionSB.Database = "KPITeamProject";
_connection = new MySqlConnection(_connectionSB.ConnectionString);
try
{
_connection.Open();
if (!_connection.Ping())
Console.WriteLine("DataBase connection is failed");
_connection.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例4: DataBase
public DataBase()
{
MySqlConnectionStringBuilder _connectionSB = new MySqlConnectionStringBuilder();
_connectionSB.Server = "localhost";
_connectionSB.UserID = "server";
_connectionSB.Password = "1111";
_connectionSB.Database = "KPITeamProject";
_connection = new MySqlConnection(_connectionSB.ConnectionString);
try
{
_connection.Open();
if (!_connection.Ping())
Console.WriteLine("DataBase connection is failed");
_connection.Close();
Log.WriteMessage("Ping and open connection was succeed", "Start connection");
}
catch(Exception ex)
{
Log.WriteMessage(ex.Message, "Start connection");
}
}
示例5: testConnectionToDatabaseButton_Click
private void testConnectionToDatabaseButton_Click(object sender, EventArgs e)
{
try
{
string mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
var conn = new MySqlConnection {ConnectionString = mySqlConnectionString};
conn.Open();
if (conn.Ping())
{
Console.WriteLine("You have successfully connected to your database!");
ConsoleWindow.WriteLine("You have successfully connected to your database!");
connectionDisplay.BackColor = Color.Chartreuse;
connectionDisplay.Text = ("Successfully Connected to Database.");
try
{
MySQLMethods.InitializeDatabases();
}
catch (Exception exception)
{
Console.WriteLine("Error Message: " + exception.Message);
ConsoleWindow.WriteLine("Error Message: " + exception.Message);
}
}
else
{
Console.WriteLine("You have unsuccessfully connected to your database!");
ConsoleWindow.WriteLine("You have unsuccessfully connected to your database!");
connectionDisplay.BackColor = Color.Red;
connectionDisplay.Text = ("Connection to Database Failed.");
}
conn.Close();
}
catch (MySqlException ex)
{
connectionDisplay.BackColor = Color.Red;
connectionDisplay.Text = ("Connection to Database Failed.");
Console.WriteLine("Error Code: " + ex.ErrorCode);
Console.WriteLine("Error Message " + ex.Message);
ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode);
ConsoleWindow.WriteLine("Error Message " + ex.Message);
}
}
示例6: MainSettings_Load
private void MainSettings_Load(object sender, EventArgs e)
{
if (Settings.Default.clickToEmptyTextBoxes)
{
clickEmptyTextBoxChecker.Checked = true;
}
else
{
if (Settings.Default.clickToEmptyTextBoxes == false)
{
clickEmptyTextBoxChecker.Checked = false;
}
}
if (Settings.Default.minimizeHomeWentEventLoads)
{
minimizeHomeCheckbox.Checked = true;
}
else
{
if (Settings.Default.minimizeHomeWentEventLoads == false)
{
minimizeHomeCheckbox.Checked = false;
}
}
if (Settings.Default.clearConsoleOnToggle)
{
clearConsoleOnToggleCheckBox.Checked = true;
}
else
{
if (Settings.Default.clearConsoleOnToggle == false)
{
clearConsoleOnToggleCheckBox.Checked = false;
}
}
if (Settings.Default.allowExportToTextFile)
{
allowExportToTextFileCheckBox.Checked = true;
}
else
{
if (Settings.Default.allowExportToTextFile == false)
{
allowExportToTextFileCheckBox.Checked = false;
}
}
if (Settings.Default.showQuestionButtons)
{
showQuestionButtonsCheckBox.Checked = true;
}
else
{
if (Settings.Default.showQuestionButtons == false)
{
showQuestionButtonsCheckBox.Checked = false;
}
}
if (Settings.Default.colourTeamComparisonStatistics)
{
colourTeamComparisonStatisticsCheckBox.Checked = true;
}
else
{
if (Settings.Default.colourTeamComparisonStatistics == false)
{
colourTeamComparisonStatisticsCheckBox.Checked = false;
}
}
teamComparisonEqualValueColourDisplay.BackColor = Settings.Default.teamComparisonEqualValueColour;
usernameTextBox.Text = Settings.Default.username;
databaseIPTextBox.Text = Settings.Default.databaseIP;
databasePortTextBox.Text = Settings.Default.databasePort;
databaseUsernameTextBox.Text = Settings.Default.databaseUsername;
databasePasswordTextBox.Text = Security.DeCryptString(Settings.Default.databasePassword);
databaseNameTextBox.Text = Settings.Default.databaseName;
try
{
string mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
var conn = new MySqlConnection {ConnectionString = mySqlConnectionString};
conn.Open();
if (conn.Ping())
{
Console.WriteLine("You have successfully connected to your database!");
ConsoleWindow.WriteLine("You have successfully connected to your database!");
connectionDisplay.BackColor = Color.Chartreuse;
connectionDisplay.Text = ("Successfully Connected to Database.");
}
else
{
Console.WriteLine("You have unsuccessfully connected to your database!");
ConsoleWindow.WriteLine("You have unsuccessfully connected to your database!");
//.........這裏部分代碼省略.........
示例7: submitDataButton_Click
private void submitDataButton_Click(object sender, EventArgs e)
{
submitDataButton.Enabled = false;
if (Settings.Default.allowExportToTextFile)
{
//Write to TextFile
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var writer = new StreamWriter(saveFileDialog.FileName);
writer.WriteLine("==========================================================");
writer.WriteLine("-===============+ Human Readable Portion +===============-");
writer.WriteLine("==========================================================");
writer.WriteLine("Time Created: " + Time.GetCurrentTime());
writer.WriteLine("Scouted By: " + Settings.Default.username);
writer.WriteLine("Match #: " + Convert.ToString(matchNumber));
writer.WriteLine("Did the robot die?: " + Convert.ToBoolean(didRobotDie));
writer.WriteLine("Team Colour: " + teamColour);
writer.WriteLine("Team Name: " + Program.selectedTeamName);
writer.WriteLine("Team Number: " + Program.selectedTeamNumber);
writer.WriteLine("#########################################################");
writer.WriteLine("Auto High: Goal: " + Convert.ToString(autoHighGoal) + " Miss: " +
Convert.ToString(autoHighMiss));
writer.WriteLine("Auto Low: Goal: " + Convert.ToString(autoLowGoal) + " Miss: " +
Convert.ToString(autoLowMiss));
writer.WriteLine("Controlled High: Goal: " + Convert.ToString(controlledHighGoal) + " Miss: " +
Convert.ToString(controlledHighMiss));
writer.WriteLine("Controlled Low: Goal: " + Convert.ToString(controlledLowGoal) + " Miss: " +
Convert.ToString(controlledLowMiss));
writer.WriteLine("Hot: Goal: " + Convert.ToString(hotGoal) + " Miss: " + Convert.ToString(hotMiss));
writer.WriteLine("3-Assist: Goal: " + Convert.ToString(tripleAssistGoal) + " Miss: " +
Convert.ToString(tripleAssistMiss));
writer.WriteLine("Auto Pickup: Successful: " + Convert.ToString(autoBallPickup) + " Unsuccessful: " +
Convert.ToString(autoBallPickupMiss));
writer.WriteLine("Controlled Pickup: Successful: " + Convert.ToString(controlledBallPickup) +
" Unsuccessful: " + Convert.ToString(controlledBallPickupMiss));
writer.WriteLine("Pickup From Human: Successful: " + Convert.ToString(pickupFromHuman) +
" Unsuccessful: " + Convert.ToString(pickupFromHumanMiss));
writer.WriteLine("Pass To Another Robot: Successful: " + Convert.ToString(passToOtherRobot) +
" Unsuccessful: " + Convert.ToString(passToOtherRobotMiss));
writer.WriteLine("Truss Shot: Successful: " + Convert.ToString(successfulTruss) + " Unsuccessful: " +
Convert.ToString(unsuccessfulTruss));
writer.WriteLine("Starting Location: X: " + Convert.ToString(xStarting) + " Y: " +
Convert.ToString(yStarting));
writer.WriteLine("Driver Rating: " + driverRating);
writer.WriteLine("Auto Movement: " + Convert.ToBoolean(autoMovement));
writer.WriteLine("Comments: " + Convert.ToString(comments));
writer.WriteLine("#########################################################");
writer.WriteLine("=========================================================");
writer.WriteLine("-=============+ Computer Readable Portion +=============-");
writer.WriteLine("=========================================================");
writer.WriteLine(Convert.ToString(Program.selectedTeamNumber));
writer.WriteLine(Convert.ToString(Program.selectedTeamName));
writer.WriteLine(Convert.ToString(teamColour));
writer.WriteLine(Convert.ToString(matchNumber));
writer.WriteLine(Convert.ToString(autoHighGoal));
writer.WriteLine(Convert.ToString(autoHighMiss));
writer.WriteLine(Convert.ToString(autoLowGoal));
writer.WriteLine(Convert.ToString(autoLowMiss));
writer.WriteLine(Convert.ToString(controlledHighGoal));
writer.WriteLine(Convert.ToString(controlledHighMiss));
writer.WriteLine(Convert.ToString(controlledLowGoal));
writer.WriteLine(Convert.ToString(controlledLowMiss));
writer.WriteLine(Convert.ToString(hotGoal));
writer.WriteLine(Convert.ToString(hotMiss));
writer.WriteLine(Convert.ToString(tripleAssistGoal));
writer.WriteLine(Convert.ToString(tripleAssistMiss));
writer.WriteLine(Convert.ToString(autoBallPickup));
writer.WriteLine(Convert.ToString(autoBallPickupMiss));
writer.WriteLine(Convert.ToString(controlledBallPickup));
writer.WriteLine(Convert.ToString(controlledBallPickupMiss));
writer.WriteLine(Convert.ToString(pickupFromHuman));
writer.WriteLine(Convert.ToString(pickupFromHumanMiss));
writer.WriteLine(Convert.ToString(passToOtherRobot));
writer.WriteLine(Convert.ToString(passToOtherRobotMiss));
writer.WriteLine(Convert.ToString(successfulTruss));
writer.WriteLine(Convert.ToString(unsuccessfulTruss));
writer.WriteLine(Convert.ToString(xStarting));
writer.WriteLine(Convert.ToString(yStarting));
writer.WriteLine(Convert.ToBoolean(didRobotDie));
writer.WriteLine(Convert.ToInt16(driverRating));
writer.WriteLine(Convert.ToBoolean(autoMovement));
writer.WriteLine(Convert.ToString(comments));
writer.WriteLine("END OF FILE");
writer.Close();
}
}
//MySQL Database
//MySQL Database Connection Info
string mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
try
{
//Creating the connection to the database and opening the connection
var conn = new MySqlConnection {ConnectionString = mySqlConnectionString};
conn.Open();
//Checking if the connection is successful
if (conn.Ping())
{
Console.WriteLine("The connection to your database has been made successfully.");
//.........這裏部分代碼省略.........
示例8: Open
public void Open()
{
string connStr = "Server=" + _dbHost +
";Uid=" + _dbUser +
";Pwd=" + _dbPass +
";database=" + _dbName +
";Charset=utf8";
_conn = new MySqlConnection(connStr);
MySqlCommand command = _conn.CreateCommand();
try
{
_conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
switch (ex.Number)
{
case 0:
Debug.WriteLine("無法連線到資料庫.");
break;
case 1045:
Debug.WriteLine("使用者帳號或密碼錯誤,請再試一次.");
break;
}
}
Debug.WriteLine(_conn.Ping());
//command.CommandText = "Update user SET nickname='Admin' WHERE id = 0 ";
//command.ExecuteNonQuery();
}
示例9: submitDataButton_Click
private void submitDataButton_Click(object sender, EventArgs e)
{
UpdateLabels();
if (Settings.Default.allowExportToTextFile)
{
//Write to TextFile
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var writer = new StreamWriter(saveFileDialog.FileName);
writer.WriteLine("Time Created: " + Time.GetCurrentTime());
writer.WriteLine("FRC_Scouting_V2 Match #: " + Convert.ToString(matchNumber));
writer.WriteLine("Did the robot die?: " + didRobotDie);
writer.WriteLine("===============================================");
writer.WriteLine("Team Name: " + Convert.ToString(Program.selectedTeamName));
writer.WriteLine("Team Number: " + Convert.ToString(Program.selectedTeamNumber));
writer.WriteLine("Team Color During Match: " + teamColour);
writer.WriteLine("===============================================");
writer.WriteLine();
writer.WriteLine("Points Scored");
writer.WriteLine("Auto High Tally: " + Convert.ToString(autoHighTally));
writer.WriteLine("Auto Low Tally: " + Convert.ToString(autoLowTally));
writer.WriteLine("Manually Controlled High Tally: " + Convert.ToString(controlledHighTally));
writer.WriteLine("Manually Controlled Low Tally: " + Convert.ToString(controlledLowTally));
writer.WriteLine("Hot Goals Scored: " + Convert.ToString(hotGoalTally));
writer.WriteLine("===============================================");
writer.WriteLine("Ball Control");
writer.WriteLine("Autonomous Ball Pickups: " + Convert.ToString(autoPickupTally));
writer.WriteLine("Controlled Ball Pickups: " + Convert.ToString(controlledPickupTally));
writer.WriteLine("Missed Pickups/Loads: " + Convert.ToString(missedPickupsTally));
writer.WriteLine("===============================================");
writer.WriteLine("Comments");
writer.WriteLine(Convert.ToString(comments));
writer.WriteLine("===============================================");
writer.WriteLine("Starting Location");
writer.WriteLine("X Starting Location: " + Convert.ToString(xStarting));
writer.WriteLine("Y Starting Location: " + Convert.ToString(yStarting));
writer.WriteLine("===============================================");
writer.WriteLine("END OF FILE");
writer.Close();
}
}
//MySQL Database
//MySQL Database Connection Info
string mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
try
{
//Creating the connection to the database and opening the connection
var conn = new MySqlConnection {ConnectionString = mySqlConnectionString};
conn.Open();
//Checking if the connection is successful
if (conn.Ping())
{
Console.WriteLine("The connection to your database has been made successfully.");
ConsoleWindow.WriteLine("The connection to your database has been made successfully.");
}
//Creating the MySQLCommand object
MySqlCommand cmd = conn.CreateCommand();
//Trying to create the table
try
{
string createTable =
String.Format(
"CREATE TABLE `{0}` (`EntryID` int(11) NOT NULL,`TeamName` varchar(45) NOT NULL DEFAULT 'Default', `TeamNumber` int(11) NOT NULL DEFAULT '0',`TeamColour` varchar(45) NOT NULL DEFAULT 'Default',`MatchNumber` int(11) NOT NULL DEFAULT '0',`AutoHighTally` int(11) NOT NULL DEFAULT '0',`AutoLowTally` int(11) NOT NULL DEFAULT '0',`ControlledHighTally` int(11) NOT NULL DEFAULT '0',`ControlledLowTally` int(11) NOT NULL DEFAULT '0',`HotGoalTally` int(11) NOT NULL DEFAULT '0',`AutoPickup` int(11) NOT NULL DEFAULT '0',`ControlledPickup` int(11) NOT NULL DEFAULT '0',`MissedPickups` int(11) NOT NULL DEFAULT '0',`StartingLocationX` int(11) NOT NULL DEFAULT '0',`StartingLocationY` int(11) NOT NULL DEFAULT '0',`Comments` varchar(45) DEFAULT 'No Comment',`DidRobotDie` tinyint(4) NOT NULL DEFAULT '0',PRIMARY KEY (`EntryID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8",
Program.selectedEventName);
cmd.CommandText = createTable;
cmd.ExecuteNonQuery();
Console.WriteLine("The table: " + Program.selectedEventName + " has been created.");
ConsoleWindow.WriteLine("The table: " + Program.selectedEventName + " has been created.");
//end of creating the table
}
catch (MySqlException createException)
{
Console.WriteLine("If there is an error it is most likely because the table is already made.");
Console.WriteLine("Errorcode: " + createException.ErrorCode);
Console.WriteLine(createException.Message);
ConsoleWindow.WriteLine("If there is an error it is most likely because the table is already made.");
ConsoleWindow.WriteLine("Errorcode: " + createException.ErrorCode);
ConsoleWindow.WriteLine(createException.Message);
}
//Submit data into the database
string insertDataString =
String.Format(
"Insert into {0} (EntryID,TeamName,TeamNumber,TeamColour,MatchNumber,AutoHighTally,AutoLowTally,ControlledHigHTally,ControlledLowTally,HotGoalTally,AutoPickup,ControlledPickup,MissedPickups,StartingLocationX,StartingLocationY,Comments,DidRobotDie) values('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}');",
Program.selectedEventName, (CountRowsInDatabase() + 1),
Program.selectedTeamName,
Program.selectedTeamNumber, teamColour, matchNumber, autoHighTally, autoLowTally,
controlledHighTally, controlledLowTally, hotGoalTally, autoPickupTally, controlledPickupTally,
missedPickupsTally, xStarting, yStarting, comments, didRobotDieINT);
cmd.CommandText = insertDataString;
cmd.ExecuteNonQuery();
Console.WriteLine("Data has been inserted into the database!");
ConsoleWindow.WriteLine("Data has been inserted into the database!");
//.........這裏部分代碼省略.........
示例10: GetDataForTeam
public void GetDataForTeam(int teamNumberLocal, int selection)
{
int numberOfMatches = 0;
var AutoHighGoal = new List<double>();
var AutoHighMiss = new List<double>();
var AutoLowGoal = new List<double>();
var AutoLowMiss = new List<double>();
var ControlledHighGoal = new List<double>();
var ControlledHighMiss = new List<double>();
var ControlledLowGoal = new List<double>();
var ControlledLowMiss = new List<double>();
var HotGoal = new List<double>();
var HotMiss = new List<double>();
var TripleAssistGoal = new List<double>();
var TripleAssistMiss = new List<double>();
var AutoPickup = new List<double>();
var AutoPickupMiss = new List<double>();
var ControlledPickup = new List<double>();
var ControlledPickupMiss = new List<double>();
var PickupFromHuman = new List<double>();
var MissedPickupFromHuman = new List<double>();
var PassToAnotherRobot = new List<double>();
var MissedPassToAnotherRobot = new List<double>();
var SuccessfulTruss = new List<double>();
var UnSuccessfulTruss = new List<double>();
var DriverRating = new List<double>();
var RobotDied = new List<double>();
var AutoMovementGood = new List<double>();
var StartingX = new List<double>();
var StartingY = new List<double>();
try
{
var conn = new MySqlConnection(MySQLMethods.MakeMySqlConnectionString());
MySqlCommand cmd = conn.CreateCommand();
MySqlDataReader reader;
cmd.CommandText = String.Format("SELECT * From {0} where TeamNumber={1}",
Program.selectedEventName, teamNumberLocal);
conn.Open();
if (conn.Ping())
{
Console.WriteLine("Connected to the databse. Collecting and generating statistics now!");
ConsoleWindow.WriteLine("Connected to the databse. Collecting and generating statistics now!");
}
reader = cmd.ExecuteReader();
while (reader.Read())
{
numberOfMatches++;
AutoHighGoal.Add(Convert.ToDouble(reader["AutoHighGoal"]));
AutoHighMiss.Add(Convert.ToDouble(reader["AutoHighMiss"]));
AutoLowGoal.Add(Convert.ToDouble(reader["AutoLowGoal"]));
AutoLowMiss.Add(Convert.ToDouble(reader["AutoLowMiss"]));
ControlledHighGoal.Add(Convert.ToDouble(reader["ControlledHighGoal"]));
ControlledHighMiss.Add(Convert.ToDouble(reader["ControlledHighMiss"]));
ControlledLowGoal.Add(Convert.ToDouble(reader["ControlledLowGoal"]));
ControlledLowMiss.Add(Convert.ToDouble(reader["ControlledLowMiss"]));
HotGoal.Add(Convert.ToDouble(reader["HotGoals"]));
HotMiss.Add(Convert.ToDouble(reader["HotGoalMiss"]));
TripleAssistGoal.Add(Convert.ToDouble(reader["3AssistGoal"]));
TripleAssistMiss.Add(Convert.ToDouble(reader["3AssistMiss"]));
AutoPickup.Add(Convert.ToDouble(reader["AutoBallPickup"]));
AutoPickupMiss.Add(Convert.ToDouble(reader["AutoBallPickupMiss"]));
ControlledPickup.Add(Convert.ToDouble(reader["ControlledBallPickup"]));
ControlledPickupMiss.Add(Convert.ToDouble(reader["ControlledBallPickupMiss"]));
PickupFromHuman.Add(Convert.ToDouble(reader["PickupFromHuman"]));
MissedPickupFromHuman.Add(Convert.ToDouble(reader["MissedPickupFromHuman"]));
PassToAnotherRobot.Add(Convert.ToDouble(reader["PassToAnotherRobot"]));
MissedPassToAnotherRobot.Add(Convert.ToDouble(reader["MissedPassToAnotherRobot"]));
SuccessfulTruss.Add(Convert.ToDouble(reader["SuccessfulTruss"]));
UnSuccessfulTruss.Add(Convert.ToDouble(reader["UnsuccessfulTruss"]));
DriverRating.Add(Convert.ToDouble(reader["DriverRating"]));
if (Convert.ToInt32(reader["DidRobotDie"]) == 1)
{
RobotDied.Add(1);
}
if (Convert.ToInt32(reader["AutoMovement"].ToString()) == 1)
{
AutoMovementGood.Add(Convert.ToDouble(reader["AutoMovement"]));
}
StartingX.Add(Convert.ToDouble(reader["StartingX"]));
StartingY.Add(Convert.ToDouble(reader["StartingY"]));
}
conn.Close();
}
catch (MySqlException e)
{
Console.WriteLine("Error Code: " + e.ErrorCode);
Console.WriteLine("Error Message: " + e.Message);
ConsoleWindow.WriteLine("Error Code: " + e.ErrorCode);
ConsoleWindow.WriteLine("Error Message: " + e.Message);
Notifications.ErrorOccured("Looks like something went wrong. Check console for the error message");
}
if (selection == 1)
{
try
{
_autoHighMean[0] = AutoHighGoal.Average();
_autoHighStandardDeviation[0] = CalculateStdDev(AutoHighGoal);
//.........這裏部分代碼省略.........
示例11: PingUpdatesState
public void PingUpdatesState()
{
MySqlConnection conn2 = new MySqlConnection(GetConnectionString(true));
conn2.Open();
KillConnection(conn2);
Assert.IsFalse(conn2.Ping());
Assert.IsTrue(conn2.State == ConnectionState.Closed);
conn2.Open();
conn2.Close();
}
示例12: updateTable
public void updateTable(bool noChange = false)
{
Process plink = null;
if (Properties.Settings.Default.SSHtunnel)
{
try
{
sqlconn.Server = @"127.0.0.1";
sqlconn.Port = uint.Parse(Properties.Settings.Default.SSHPort);
ProcessStartInfo psi = new ProcessStartInfo(Properties.Settings.Default.plinkPath);
psi.Arguments = "-ssh -l " + Properties.Settings.Default.SSHUser + " -L " + Properties.Settings.Default.port + ":localhost:" +
Properties.Settings.Default.SSHPort + " -pw " + Properties.Settings.Default.SSHPass + " " + Properties.Settings.Default.server;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
plink = Process.Start(psi);
}
catch
{
debugOutput("SSH-Tunnel konnte nicht aufgebaut werden");
return;
}
}
else
{
sqlconn.Server = Properties.Settings.Default.server;
sqlconn.Port = Properties.Settings.Default.port;
}
sqlconn.UserID = Properties.Settings.Default.user;
sqlconn.Password = Properties.Settings.Default.password;
sqlconn.Database = Properties.Settings.Default.database;
string table = Properties.Settings.Default.table;
EntryTable.TableName = table;
using (MySqlConnection connection = new MySqlConnection(sqlconn.ConnectionString))
{
try
{
connection.Open();
if (!connection.Ping())
{
throw new Exception("No Connection to Server. \r\n Connection: " + sqlconn.ConnectionString);
}
if (!noChange)
{
MySqlCommand del = new MySqlCommand(@"TRUNCATE TABLE " + sqlconn.Database + "." + table, connection);
del.ExecuteNonQuery();
MySqlDataAdapter adapter = new MySqlDataAdapter(@"SELECT * FROM " + sqlconn.Database + "." + table, connection);
MySqlCommandBuilder builder = new MySqlCommandBuilder(adapter);
adapter.ContinueUpdateOnError = true;
adapter.Update(EntryTable);
}
debugOutput("Successful", 1);
}
catch (Exception ex)
{
debugOutput(ex.Message.ToString());
//string tmp = "";
//if (plink != null)
// tmp = plink.StandardOutput.ReadToEnd();
//debugOutput(ex.Message.ToString() + tmp);
}
}
try
{
plink.StandardInput.WriteLine("exit");
plink.Kill();
plink.Dispose();
}
catch { }
if (!noChange)
EntryTable.Clear();
}
示例13: SetUpConnection
private void SetUpConnection()
{
string conString = "SERVER=" + _configuration.database + ";" +
"DATABASE=Computation;" +
"UID=" + _configuration.user +
";PASSWORD=" + _configuration.password + ";";
_sqlConnection = new MySqlConnection(conString);
try
{
_sqlConnection.Open();
if (!_sqlConnection.Ping())
{
MessageBox.Show("Die Verbindung zur Datenbank konnte nicht hergestellt werden", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
//Environment.Exit(-1);
}
}
catch (Exception)
{
MessageBox.Show("Die Verbindung zur Datenbank konnte nicht hergestellt werden", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
//Environment.Exit(-1);
}
_sqlConnection.Close();
}