Error when run WPF Application in other Computer - c#

First of all, I am new to WPF application.
I have create WPF application login form which require input username and password from the users. This application then will open new form if the username and password matching with the one on sql server database.
private void Login_bt_Click(object sender, RoutedEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=\\isdsvr04\LED\LDEMPDB\MPDB.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter("Select * From [Table]
where Username='" + username_tx.Text + "' and Password='" +
password_tx.Text + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
Globals.username = username_tx.Text;
Globals.FullName = dt.Rows[0]["FullName"].ToString();
Globals.userImage = dt.Rows[0]["UserImage"].ToString();
Globals.NickName = dt.Rows[0]["NickName"].ToString();
this.Hide();
Window1 f = new Window1();
f.Show();
}
else
{
MessageBox.Show("Please check your username and password");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.InnerException == null ? ex.Message : ex.InnerException.Message);
}
}
'''
This work fine on my PC. However when I run this on other PC, the exception generate error "The systems cannot find the file specified". The sql server database is located on the public server in which all computer can access through it.

Related

SqlAdapter does not recognize my table: exception "invalid object name"

i am building small login form and this issue showed up.
I SQL server connected (i tried couple different connections aswell), table should be right, i don't see any issue in that.
I have tried already couple different SQL connections and new databases and tables.
private void BtnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(#"Data Source=MYDESKTOP\MSSQLSERVER01;Integrated Security=True;Connect Timeout=30;Encrypt=False; TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
SqlDataAdapter sqa = new SqlDataAdapter ("SELECT COUNT (*) from LOGINFORM where USERNAME ='" + txtUsername.Text +"' and PASSWORD = '" + txtPassword.Text + "'", con);
DataTable dt = new DataTable();
sqa.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Form2 main = new Form2();
main.Show();
}
else
{
MessageBox.Show("Username/Password is incorrect. Please try again");
}
}
Expection unhandled invalid object name "LOGINFORM"
You need to set your "Initial Catalog" in your connection string. If you don't specify it, then the default database will be "master", which likely does not contain your table "LOGINFORM". Another option is to fully qualify the table name in your query like databasename.owner.tablename.

c# windows form ( i want to update the data in the database )

i want to update the password when i login with a user account
like this
i created an account the data saved to the data base then i want to change the data for the same account basically change the password for that account
so i tried this
public partial class User_Ditails : Form
{
public OleDbConnection conect = new OleDbConnection();
public User_Ditails()
{
InitializeComponent();
conect.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Mhamad\Desktop\form\Sign_Up.mdb;
Persist Security Info=False;";
}
private void button1_Click(object sender, EventArgs e)
{
OleDbDataAdapter ASDF = new OleDbDataAdapter ("SELECT COUNT(*) FROM Sign_Up WHERE UserName='"+UserName.Text+"' AND Password='"+Old_Pass.Text+"'",conect);
DataTable DS = new DataTable();
ASDF.Fill(DS);
errorProvider1.Clear();
if (DS.Rows[0][0].ToString() == "1")
{
if (New_Pass.Text==Confirm_Pass.Text)
{
if (New_Pass.Text.Length > 6)
{
OleDbDataAdapter cc = new OleDbDataAdapter("update Sign_Up set Password='" + New_Pass.Text + "' where UserName='" + UserName.Text + "' and Password='" + Old_Pass.Text + "'", conect);
DataTable DF = new DataTable();
cc.Fill(DF);
errorProvider1.Clear();
MessageBox.Show("Password Has Changed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
errorProvider1.SetError(New_Pass, "Set Minimun 6 Charector");
}
}
else
{
errorProvider1.SetError(New_Pass, "UnMatch Password");
errorProvider1.SetError(Confirm_Pass, "UnMatch Password");
}
}
else
{
errorProvider1.SetError(UserName,"Incorrect UserName");
errorProvider1.SetError(Old_Pass, "Incorrect Password");
}
but i always get this error
System.Data.OleDb.OleDbException: 'Syntax error in UPDATE statement.'
on this code cc.Fill(DF);

How to authorize in xamarin android via mysql database

How to authorize in xamarin android via mysql database?
Here code:
MysqlCommand com = new MysqlCommand("SELECT test_log, test_pass FROM login WHERE test_log =#log AND test_pass =#pass", mycon);
mycon.Open();
com.Parameters.AddWithValue("#log", login1.Text);
com.Parameters.AddWithValue("#pass", password1.Text);
MySqlReader dr = com.ExcecuteReader();
download all links and connected MysqlClient. please need help!
How to authorize in xamarin android via mysql database?
I don't know what library are you currently using, but you can have a try of MySQL Plugin. You can add it to your project through Component->Edit Components-> Get More Components->Search MySQL Plugin on the search bar.
And then you can access MySQL using following codes:
public bool loginFromMySQL()
{
MySqlConnection sqlconn=null;
bool loginSuccess=false;
try
{
string connsqlstring = "Server=serverAddress;Port=3306;database=database Name;User Id=userName;Password=user password;charset=utf8";
sqlconn = new MySqlConnection(connsqlstring);
sqlconn.Open();
DataSet tickets = new DataSet();
string userName = "userName";
string password = "password";
string queryString = "select * from login where userName='" + userName + "' and password='" + password + "'";
MySqlDataAdapter adapter = new MySqlDataAdapter(queryString, sqlconn);
adapter.Fill(tickets, "login");
if (tickets.Tables["login"].Rows.Count > 0)
{
//login success
loginSuccess=true;
}
else
{
loginSuccess=false;
}
}
catch (Exception e)
{
Console.Write(e.Message);
}
sqlconn.Close();
return loginSuccess;
}

How to make a connection with local host database through visual studio 2008 using c#?

I have created a sample database in MySql workbench. I am working on a smart device windows application and i am trying to connect my local host where i have my sample database to the login button i have created on the login form. My coding
private void Login_Click(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection("server=localhost;User Id= ;database= ");
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM login where Username = '" + textBox1.Text+ "' and Password = '" + textBox2.Text + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString()== "1")
{
MainMenuform ps = new MainMenuform();
ps.Show();
this.Hide();
}
else
{
MessageBox.Show("Please check Username and Password");
}
}
So, when i try the above coding, its giving me an error "Cannot connect to the specified MySql host you specified". My code seems alright but i am still getting this error. Please help.

Login Page C# .SDF

I am trying to create an application that allows a user to log in using .sdf, there is not much on the internet about this!
Could really do with some pointers.
This is what I currently have but I believe it is a pile of mess as no matter what I type in each text box it will redirect me to Form2 (which is kinda expected). I know I need an if statement somewhere but not sure how to implement:
private void Login_Click(object sender, EventArgs e)
{
using (SqlCeConnection yourConnection = new SqlCeConnection("Data Source=C:\\Users\\Username\\Documents\\Databases\\New Folder\\Login.sdf"))
{
string query = "SELECT * FROM tbl_employees where Username like '" + textBox1.Text + "' AND Password like '" + textBox2.Text +"'";
SqlCeDataAdapter dA = new SqlCeDataAdapter(query, yourConnection);
SqlCeCommandBuilder cBuilder = new SqlCeCommandBuilder(dA);
this.Hide();
Form2 secondForm = new Form2();
secondForm.ShowDialog();
}
}
First, SQL Server CE database i.e .sdf file is just another storage file. It is very very light and portable version of SQL Server.
But, at most, your code and logicwould be similar to the one for SQL Server. Just different classes. i.e SqlCeConnection, SqlCeCommand and so on.
Now you need to verify that your connectionString is correct.
string connectionString ="data source=physical path to .sdf file;
password=pwdThtUSet; persist security info=True";
using (SqlCeConnection yourConnection = new SqlCeConnection(connectionString))
{
....your logic
}
Now, in your query to search for the username and password combination matching row, don't do it with like because you need exact match.
so do it like:
string query = "SELECT * FROM tbl_employees where Username ='" + textBox1.Text + "' AND Password ='" + textBox2.Text +"'";
SqlCeDataAdapter dA = new SqlCeDataAdapter(query, yourConnection);
DataTable dt = new DataTable();
dA.Fill(dt);
if(dt.Rows.Count>0)
{
this.Hide();
Form2 secondForm = new Form2();
secondForm.ShowDialog();
}
Try this only after the login criterion has been met:
if (usernametextbox.Text.Equals("form2username", StringComparison.InvariantCultureIgnoreCase)) {
// code for redirection to form2
Hide();
con.Close();
} else {
if (usernametextbox.Text.Equals("form3username", StringComparison.InvariantCultureIgnoreCase)) {
// code for redirection to form3
Hide();
con.Close();
}
}

Categories