SQL server access denied from web service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D Godwin

    SQL server access denied from web service

    I am running a web service on my local machine (using standard VS.NET test
    pages) that is attempting to access a SQL database on a network server. C#
    code looks something like this:

    [WebMethod]
    public string GetSomething()
    {
    SqlConnection con = new SqlConnection() ;
    con.ConnectionS tring =
    ConfigurationSe ttings.AppSetti ngs["connectstr ing"].ToString();
    con.Open();
    ...
    }

    The problem is that the Open() statement always yields a "SQL Server does
    not exist or access denied" message. The same code works fine when run from
    a WinForms app, so I know that my connection string is good. Is this a
    permissions issue or am I missing a setting somewhere?

    Thanks in advance.
    David


  • Keenan Newton

    #2
    Re: SQL server access denied from web service

    Can we see the conenction string as it looks inside the config file.
    Also if you are using a trusted connection, it is quite possible the
    ASP.Net web service does not have the proper rights to the sql server

    Comment

    • D Godwin

      #3
      Re: SQL server access denied from web service

      Minus the actual values, it looks like this:
      "Data Source=serverna me;User ID=u;Password=p ;Initial Catalog=c;Persi st
      Security Info=True;"


      Comment

      • Keenan Newton

        #4
        Re: SQL server access denied from web service

        Are you using the same config file in both circumstances?

        Comment

        • D Godwin

          #5
          Re: Solution

          As suspected, it was a permissions issue. Fixing it involved using
          impersonation as described by MS at:




          Comment

          • jimskipper

            #6
            Re: SQL server access denied from web service


            I have the exact same problem with a VB.NET Web Service.

            Identical code in a WinForms app succeeds, but the web service fail
            with "SQL Server does
            not exist or access denied." with the service on my local computer o
            on our IIS server.

            D Godwin wrote:[color=blue]
            > *I am running a web service on my local machine (using standar
            > VS.NET test
            > pages) that is attempting to access a SQL database on a networ
            > server. C#
            > code looks something like this:
            >
            > [WebMethod]
            > public string GetSomething()
            > {
            > SqlConnection con = new SqlConnection() ;
            > con.ConnectionS tring =
            > ConfigurationSe ttings.AppSetti ngs["connectstr ing"].ToString();
            > con.Open();
            > ....
            > }
            >
            > The problem is that the Open() statement always yields a "SQL Serve
            > does
            > not exist or access denied" message. The same code works fine whe
            > run from
            > a WinForms app, so I know that my connection string is good. Is thi
            > a
            > permissions issue or am I missing a setting somewhere?
            >
            > Thanks in advance.
            > David[/color]


            -
            jimskippe
            -----------------------------------------------------------------------
            Posted via http://www.mcse.m
            -----------------------------------------------------------------------
            View this thread: http://www.mcse.ms/message1431533.htm

            Comment

            Working...