How to connect SQL Server 2008 with IIS 7 on Windows Server 2008

amazon ec2iis-7sql-server-expresswindows-server-2008

I am using Amazon EC2 server, with Windows Server. It has installed SQL Server 2008 R2 Express and IIS7. I have made a web site, and want to test this web app. But it is not connecting to the SQL Server. I have tried different connection strings. But it is giving this error:

Server Error in '/' Application.
Cannot open database "Avon" requested
by the login. The login failed. Login
failed for user 'NT AUTHORITY\NETWORK
SERVICE'.

I have tried to change it from windows authentication to SQL Server authentication and vice versa. But same error.

My connection string is

connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Avon.mdf;Integrated Security=True;User Instance=true;"

I have copied Avon.mdf and Avon.ldf file into App_data. I want it to connect either by local server, or by IP address.

I appreciate your answers.
Thanks

Best Answer

If the identity under which the application is running does not have access to the database, you will need to provide user name and password in the connection string.

Example:
Password=somepassword;Persist Security Info=True;User ID=someuserid;Initial Catalog=DatabaseName;Data Source=.\SQLEXPRESS