SQLConnection.Open() in a WebService

Discussion in 'ASP .Net Web Services' started by Stephen, Jul 16, 2004.

  1. Stephen

    Stephen Guest

    I'm experiencing a strange problem that has me baffled. I created a
    webservice with a webmethod that connects to a remote MS SQL Server:

    SqlConnection mySQLConnection = new SqlConnection();
    mySQLConnection.ConnectionString="data source=192.168.30.44;
    uid=rocky;pwd=raccoon;database=myDatabase";
    mySQLConnection.Open();

    This code works fine in the Windows app with either SQL Server 7 or
    2000. It also works fine in the webservice app with one server, which
    happens to be SQL Server 7. It does not work with the other server,
    running SQL Server 2000. It generates the error "server does not
    exist or access is denied" at mySQLConnection.Open().

    I can connect to either database using Enterprise Manager.

    Can anybody help?

    TIA!
     
    Stephen, Jul 16, 2004
    #1
    1. Advertising

  2. Stephen

    Dale Guest

    Change your connection string to:

    "data source=192.168.30.44;user=rocky;password=raccoon;initial
    catalog=myDatabase"

    You're trying to mix OleDb and SqlClient.

    Search the .Net Framework documentation for an article titled "Accessing SQL
    Server from a Web Application" and it will give you many examples of
    connecting to SQL Server under differing conditions.

    Dale


    "Stephen" <> wrote in message
    news:...
    > I'm experiencing a strange problem that has me baffled. I created a
    > webservice with a webmethod that connects to a remote MS SQL Server:
    >
    > SqlConnection mySQLConnection = new SqlConnection();
    > mySQLConnection.ConnectionString="data source=192.168.30.44;
    > uid=rocky;pwd=raccoon;database=myDatabase";
    > mySQLConnection.Open();
    >
    > This code works fine in the Windows app with either SQL Server 7 or
    > 2000. It also works fine in the webservice app with one server, which
    > happens to be SQL Server 7. It does not work with the other server,
    > running SQL Server 2000. It generates the error "server does not
    > exist or access is denied" at mySQLConnection.Open().
    >
    > I can connect to either database using Enterprise Manager.
    >
    > Can anybody help?
    >
    > TIA!
     
    Dale, Jul 18, 2004
    #2
    1. Advertising

  3. Stephen

    Dale Guest

    In my string, change "user=rocky" to "user id=rocky"

    It's after midnight and until the reply posted, I didn't even catch my own
    error.

    Dale

    "Dale" <> wrote in message
    news:#...
    > Change your connection string to:
    >
    > "data source=192.168.30.44;user=rocky;password=raccoon;initial
    > catalog=myDatabase"
    >
    > You're trying to mix OleDb and SqlClient.
    >
    > Search the .Net Framework documentation for an article titled "Accessing

    SQL
    > Server from a Web Application" and it will give you many examples of
    > connecting to SQL Server under differing conditions.
    >
    > Dale
    >
    >
    > "Stephen" <> wrote in message
    > news:...
    > > I'm experiencing a strange problem that has me baffled. I created a
    > > webservice with a webmethod that connects to a remote MS SQL Server:
    > >
    > > SqlConnection mySQLConnection = new SqlConnection();
    > > mySQLConnection.ConnectionString="data source=192.168.30.44;
    > > uid=rocky;pwd=raccoon;database=myDatabase";
    > > mySQLConnection.Open();
    > >
    > > This code works fine in the Windows app with either SQL Server 7 or
    > > 2000. It also works fine in the webservice app with one server, which
    > > happens to be SQL Server 7. It does not work with the other server,
    > > running SQL Server 2000. It generates the error "server does not
    > > exist or access is denied" at mySQLConnection.Open().
    > >
    > > I can connect to either database using Enterprise Manager.
    > >
    > > Can anybody help?
    > >
    > > TIA!

    >
    >
     
    Dale, Jul 18, 2004
    #3
  4. Thanks for the reply Dale.

    I've tried that connection string without success. There's something
    odd going on... I think I have the syntax correct. I wonder if there's
    some server setting I've neglected.

    The same code works fine from a Windows app, but not from a webservice.
    Very strange.

    -Steve



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Steve Kearney, Jul 19, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark

    Can't open a SqlConnection

    Mark, May 9, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    760
  2. Kevin Spencer
    Replies:
    3
    Views:
    3,035
    Kevin Spencer
    Aug 15, 2003
  3. Nevyn Twyll
    Replies:
    4
    Views:
    4,407
    Juan T. Llibre
    Mar 19, 2005
  4. Nils Magnus Englund

    "Timeout expired" when calling SqlConnection.Open()

    Nils Magnus Englund, Aug 23, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,725
    Nils Magnus Englund
    Aug 24, 2005
  5. pratham
    Replies:
    3
    Views:
    739
    sloan
    Aug 31, 2006
Loading...

Share This Page