SqlConnection localhost bad username

This is my first time trying to use a database in ASP.Net, and I have a problem:

My database is located on my computer (localhost), and it throws an exception when I click the submit button:

SQLException was not handled 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 don’t have a username, right ?!

+4
source share
3 answers

You need a username and password, or you need to use built-in protection, which means that your Windows credentials are used.

You can add integrated protection to your connection as follows:

 SqlConnection connection = new SqlConnection("server = localhost ;integrated security=SSPI; database = Movies;"); 

A good resource for connection strings is http://www.connectionstrings.com

+3
source

SQL Server always requires a username, whether on your computer or on a remote machine.

I would suggest looking at www.asp.net or trying Google to find out how you set up your patricular version of SQL Server.

+1
source

Check the site for connections if you have a problem creating a connection string

+1
source

Source: https://habr.com/ru/post/1386327/


All Articles