This is my first time trying to use a database in ASP.Net, and I have a problem here:
My database is on my computer (localhost), and it throws an exception on me when I click the “submit” button :
SQLException was unhandled by user code. Login failed for user “.
protected void Register_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("server = localhost ;uid=; Password= database = Movies;");
connection.Open();
//FirstName***********
string firstName = UsernameTextBox.Text;
string sqlquery = ("INSERT INTO [Movie] (FirstName) VALUES (' " +FirstNameTextBox.Text + " ' ");
SqlCommand command = new SqlCommand(sqlquery , connection);
command.Parameters.AddWithValue("FirstName", firstName);
Since the server is on my computer, I dont have any username, right?!
You do need a username and password, or else you need to use integrated security, which means that your windows credentials are used.
You can add integrated security to your connection as follows:
A good resource for connection strings is http://www.connectionstrings.com