Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
System.Data.SqlClient.SqlException
Daniel Koh
Oct 10 2017 12:03 AM
236
Reply
Hi guys i'm learning C# now and am trying to create a login application and one of the lines for sql gave me this error
System.Data.SqlClient.SqlException: 'An attempt to attach an auto-named database for file C: \*****\**********\Documents\Data.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.'
this is the code i was learning:
SqlConnection sqlConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C: \*****\**********\Documents\Data.mdf;Integrated Security=True;Connect Timeout=30;");
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("Select Count(*) From Login where Username='" + textBox1.Text + "' and Password = '" + textBox2.Text + "'",sqlConnection);
DataTable dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
if (dataTable.Rows[0][0].ToString() == "1")
{
this.Hide();
Form2 MainMenu = new Form2();
MainMenu.Show();
}
else
{
MessageBox.Show("Please check your username and password");
}
HELP
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to get the year wise employee as per the promotion
How to manage patches of database?