locked
The ConnectionString property has not been initialized RRS feed

  • Question

  • Hello,

    VS 2005 + SQL 2005

    This works:
    Code Snippet

    connectionString="server = steve01\sqlexpress; database = servicemasterTEST; user id = sa; pwd="



    This does not:
    Code Snippet

    connectionString="server = steve01\sqlexpress; database = servicemasterTEST; trusted_connection = yes"



    This also doesn't work:
    Code Snippet

    connectionString="server = steve01\sqlexpress; database = servicemasterTEST; integrated security = true"


    The connection string is located in the web.config file as tihs is a connection string for a web service.

    I have been to www.connectionstrings.com and looked and tried them as well.

    I can't userstand why it would let me use the user name and password but not the windows authenication.

    I have started sql server management studio and entered for both sql authenication and also for windows authentication. Both of them work in sql server management studio.

    I have check sql server to see if it running, and also set it for local and remote.

    Can anyone tell me if I am missing something simple here.

    Many thanks,

    Steve
    Tuesday, August 14, 2007 11:20 PM

Answers

  • ASP.Net application will impersonate the user as ASPNET (Windows XP) or NETWORKSERVICE (Windows 2003) when you use windows authenciation.  These built-in users do not, by default, have sufficient right to read or write your database.

     

    One way to work around is to add these users to your database and grant sufficient right to them.  Another way is to impersonate your ASP.Net application to use an identity that is permitted by the database.

    Wednesday, August 15, 2007 2:10 AM
  • If you have SQL Server Management Studio, you can add ASPNET as a new user (look for Security -> Logins ->New User).  After that you need to map this user to the database.  Go to that database and grant sufficient right to this user (Database-> [yourDatabaseName]->property->permission).

    Wednesday, August 15, 2007 11:14 AM

All replies

  • ASP.Net application will impersonate the user as ASPNET (Windows XP) or NETWORKSERVICE (Windows 2003) when you use windows authenciation.  These built-in users do not, by default, have sufficient right to read or write your database.

     

    One way to work around is to add these users to your database and grant sufficient right to them.  Another way is to impersonate your ASP.Net application to use an identity that is permitted by the database.

    Wednesday, August 15, 2007 2:10 AM
  • Hello,

    Thanks for your reply.

    I added the following into the web.config file
    <identity impersonate = "true" />

    However, the above still doesn't work.

    I am using sql server 2005. How do you add the aspnet user account to the database?

    Thanks,

    Steve
    Wednesday, August 15, 2007 10:40 AM
  • If you have SQL Server Management Studio, you can add ASPNET as a new user (look for Security -> Logins ->New User).  After that you need to map this user to the database.  Go to that database and grant sufficient right to this user (Database-> [yourDatabaseName]->property->permission).

    Wednesday, August 15, 2007 11:14 AM
  • Hello,

    Thanks for the help.

    However, I am still experiencing some problems.

    This is what I did:
    Security - logins - New login

    Search - Advanced - Find Now

    I added the ASPNet

    Clicked OK

    On my database - security - right clicked user - new user
    Browsed for the login name, which is STEVE01\ASPNET. For the user name i entered this again.

    Clicked ok.

    Refreshed users, to check to see if the user had been added. Everything ok.

    However, when i run my web service, i still get this = "The ConnectionString property has not been initialized"

    Many thanks for any other suggestions,

    Steve
    Wednesday, August 15, 2007 11:49 AM
  • This may sound strange, but is there any chance that the error message is actually telling the truth? That for some reason, the connection string is not initialized?

     

    Are you able to break in the debugger where this exception occurs? If so, look at the .ConnectionString and see if it is set.

     

    Thursday, August 16, 2007 12:13 AM
    Moderator
  • You did not follow all steps that I told you.  Did you grant sufficient permission (e.g. db_datareader, db_datawriter, etc) to Steve01\ASPNET to use your database?

    Thursday, August 16, 2007 1:34 AM
  • Problem solved,

     

    I added the permisson to the aspnet account and removed the following line from the web.config file.

     

    <impersonate identity = true>

     

    Everything works now, thanks for your help,

     

    Steve

     

    Saturday, August 18, 2007 1:40 PM