1
votes

I've tried to collect data in a WCF service, but I always get error

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

This happen when I uninstall SQL Server 2005 and replace it with SQL Server 2008. Please someone help me

Here's my code

public DataTable fillData(string connection, string tableName)
{
    DataTable dt = new DataTable();

    using (SqlConnection con = new SqlConnection())
    {
        con.Open();

        using (SqlDataAdapter da = new SqlDataAdapter("select * from " + tableName, con)) 
        {
            da.Fill(dt);
        }
    }

    return dt;
}
1

1 Answers

1
votes

You did not give any details to connection object and opening the connection object. You are probably getting exception due to this. Use other version of SqlConnection constructor SqlConnection(string) and pass the connection string you have in parameter in Constructor of SqlConnection.

As a additional note use the try catch to handle the exception

public DataTable fillData(string connection, string tableName)
{
    DataTable dt = new DataTable();
    try
    {
       using (SqlConnection con = new SqlConnection(connection))
       {
           con.Open();
           using (SqlDataAdapter da = new SqlDataAdapter("select * from " + tableName,con))
           {
                da.Fill(dt);
           }
       }
     }
     catch(Exception ex)
     {
         //You may log exception here and show some message to user
     }
    return dt;
}

As far as the message you are getting indicates that the WCF service settings does not permit to show the details of internal server error. You can permit this during development to get the exact error message using ServiceBehaviorAttribute.IncludeExceptionDetailInFaults property.

ServiceBehaviorAttribute.IncludeExceptionDetailInFaults

Gets or sets a value that specifies that general unhandled execution exceptions are to be converted into a System.ServiceModel.FaultException of type System.ServiceModel.ExceptionDetail and sent as a fault message. Set this to true only during development to troubleshoot a service