Chris Norris
Chris Norris

Reputation: 161

Posting data to a SQL Server 2008 database from web service yields error

I am trying to use c# to post data to a web service (that I wrote). This web service runs fine when I run it from my local machine. As soon as I move to it a server (within my building), it throws this error:

Server was unable to process request.
---> ExecuteNonQuery: Connection property has not been initialized.

Any ideas what might be causing this?

I have checked:

Upvotes: 1

Views: 331

Answers (3)

Chris Norris
Chris Norris

Reputation: 161

I was able to solve my problem. I was actually authenticating to the wrong server. So once I pointed to the right server, it worked. Cockpit trouble here.

Upvotes: 0

John Woo
John Woo

Reputation: 263743

Connection property has not been initialized is usually thrown by the Connection object due to ConnectionString that was not supplied or incorrect information.

using (SqlConnection connection = new SqlConnection())
{
    // don't forget this line.
    connection.ConnectionString = "valid connection string here";
    // then pass the connection to your command object
    using (SqlCommand command = new SqlCommand())
    {
         command.Connection = connection;
         // other codes
    }
}

Additional Note:

SQL Server 2008 Connection Strings formats...

Upvotes: 2

Eric J.
Eric J.

Reputation: 150118

It seems like the connection has not been associated with the command object.

Check and see if there's a problem creating the connection object. Is it properly initialized? Is it using a correct connection string?

Upvotes: 1

Related Questions