0
即時通訊和MYSQL新手,所以不要判斷我。所以基本上即時使用此代碼連接到我的MYSQL數據庫並在數據庫中創建一個帳戶,這段代碼在我的筆記本電腦上工作得很好,但dossent似乎在我的桌面上工作,我不知道爲什麼,任何sugestions?C#MYSQL數據庫連接工作在筆記本電腦上,但不在桌面上
private void createaccountBT_Click(object sender, RoutedEventArgs e)
{
MySqlConnection connection;
string server = "********";
string database = "********";
string uid = "********";
string password = "********";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
try
{
connection.ConnectionString = connectionString;
connection.Open();
MySqlCommand cmd = new MySqlCommand("insert into users (Username,Password) values(@Username,@Password)", connection);
cmd.Parameters.AddWithValue("@Username", createusernametxt.Text);
cmd.Parameters.AddWithValue("@Password", pwboxcr8user.Password);
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Account sucesfully created");
}
catch (Exception ex)
{
MessageBox.Show(" an error occured. Please try again later.");
}
}
編輯:這是一個在線的服務器和所有正確寫入其直接複製從那裏就像一個魅力的筆記本電腦粘貼,也標誌着我的東西作爲一個答案,我不認爲如何取消它,因爲這是我的第一篇文章,對此感到遺憾。
如果它在地方A,而不是地方B,那麼代碼很可能不是你的問題:嘗試登錄到mysql使用mysql命令行工具在兩個系統上,看看你得到了什麼樣的反應。 –
服務器未設置爲localhost,對不對? –
你的代碼沒有問題。在桌面上試用時,請確保連接變量(服務器,數據庫,用戶名,密碼)被調整爲連接到桌面上的數據庫,而不是針對您的筆記本電腦。如果您在兩種情況下都連接到相同的數據庫,那麼在筆記本電腦或臺式機上還是第三個系統? – quest4truth