Help me with Sqlconnection string in C#,please

  • Thread starter Thread starter djozy
  • Start date Start date
D

djozy

I want to make asp.net application in C# that is connected
with SQL Server database. When I put this connection
string:
SqlConnection conn = new SqlConnection(
"user id=;" +
"password=;server=localhost;" +
"Trusted_Connection=yes;"+
"database=Knjiznica;" +
"connection timeout=30");

try
{
conn.open();
}

catch(SqlException sqle)
{
this.TextBox1 .Text =sqle.Message ;
}
it throws me this error in textbox1: Login failed for
user 'JOSIP-SKY2IGFE7\ASPNET'. where JOSIP-SKY2IGFE7 is
name of my computer.
When I make windows application and put the same
connection string it works!!
What do I need to do that my web applications also works?
Thank you
 
djozy,

The reason this is failing is that you are using the Trusted_Connection
property, which means that it will ignore the user id and password fields.
If you have a specific account to login, remove the Trusted_Connection
property and then place the user name and password there.

The problem arises because ASP.NET (which you are running this in), runs
under the ASPNET user account by default. This account has very limited
permissions. So, to get around that, you either have to change the user
that the page runs under (through the web.config file for the directory), or
elevating the privledges of the ASP.NET user.

Hope this helps.
 
Thank you for your help,but when I launch web.config from
directory where is my application it opens in IE and
throws me this:
This type of page is not served.
Description: The type of page you have requested is not
served because it has been explicitly forbidden. The
extension '.config' may be incorrect. Please review the
URL below and make sure that it is spelled correctly.
What to do?How to open it,or how and where can I eveluate
the privledges of ASP.NET user? I can't find a paper where
I had put my login,and server on wich I work is
localserver.It is in fact my own computer.I have installed
win2000 advanced server on it.
Thank you for your patient.
 
You can't serve up web.config. Rather, you have to edit the file to
change the configuration. It will be in the same directory as your ASPX
file that is trying to access the page.
 
Back
Top