Take the 2-minute tour ×

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;");
        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?!

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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:

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

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

share|improve this answer
Thanks for the quick response : –  thormayer Dec 14 '11 at 13:28
although it doesnt work . it says : "Keywords not supporeted" , and refering to the integrated_security –  thormayer Dec 14 '11 at 13:28
@user1054375 use "Integrated Security" without the underscore. –  vcsjones Dec 14 '11 at 13:30
oh , thanks, that worked out well! thanks again! –  thormayer Dec 14 '11 at 13:35
Have corrected it. –  Jon Egerton Dec 14 '11 at 14:12

SQL server always requires a username, whether it's on your machine or a remote machine.

I'd suggest looking www.asp.net or try Google to find out how you configure your patricular version of SQL Server

share|improve this answer

Check this site for connectionstrings if you have problem with formating the connectionstring

share|improve this answer

Your Answer


