I am experiencing an issue '' does not belong to table in the WCF web service. This is because of the overwritten datatable by another thread with other schema. I have debugged by implementing the logs and found that the whole schema and data was changed with another database call which was called after the first one in sequence. This is really surprised for me that how the memory instance of the first datatable object is overwritten with the second one when this is not declared as static. I used thread locking but unfortunately it doesn't work. I am quit sure this is MS bug, but there might be a solution which I don't know so far.

Here is the sequence of method calls:
First I fill the datatable with user credentials for user authentication, this datatable has only three columns and one row.
Second I fill another datatable with some other data which is required to process the request, then I fill one more table which is also required to process the request.

Sometimes, the error pops up on the first datatable that '' does not belong to the table and sometimes it is appeared on the second datatable. When I logged the table schema it was totally changed with the second one.

Here is the code of first datatable:

```
public UserCredentials GetUserCredentials(string userName)
     {   
        try
        {
            UserCredentials userCredentials = null;

            using (SqlCommand cmd = new SqlCommand())
            {
                    DataTable dt = new DataTable("User");
                    cmd.CommandText = "dbo.[stored procedure]";
                    cmd.Connection = this.connection;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@UserName", userName);

                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        sda.SelectCommand = cmd;
                        sda.Fill(dt);
                    }

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        userCredentials = new UserCredentials();
                        userCredentials.UserName = userName;
                        userCredentials.SiteID = dt.Rows[0]["SiteID"].ToString();
                        **userCredentials.Password = dt.Rows[0]["Passphrase"].ToString();**
                    }
                }

            return userCredentials;
        }
        catch (Exception ex)
        {
            throw ex;
        }
     }

```

Second datatable:

```
public GatewayProfile GetGatewayProfile(string siteID)
        {
            Int64 gatewayID = 0;
            string submitterID = "";
            GatewayProfile gatewayProfile = null;

            try
            {
                this.OpenConnection();

                DataTable dtGateway = new DataTable("GTDetails");
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "dbo.[stored procedure]";
                    cmd.Connection = this.connection;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@SiteID", siteID);

                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        sda.SelectCommand = cmd;
                        sda.Fill(dtGateway);
                    }
                }

                if (dtGateway != null && dtGateway.Rows.Count > 0)
                {
                    gatewayProfile = new GatewayProfile();

                    if (Convert.ToBoolean(dtGateway.Rows[0]["IsDefault"]) == false)
                    {
                        gatewayID = Convert.ToInt64(dtGateway.Rows[0]["GatewayID"]);
                        submitterID = dtGateway.Rows[0]["SubmitterID"].ToString();
                    }

                    DataTable dtRoute = new DataTable("RTDetails");
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "dbo.[stored procedure]";
                        cmd.Connection = this.connection;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@GatewayID", gatewayID);
                        cmd.Parameters.AddWithValue("@SubmitterID", submitterID);

                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            sda.SelectCommand = cmd;
                            sda.Fill(dtRoute);
                        }
                    }

                    if (dtRoute != null && dtRoute.Rows.Count > 0)
                    {
                        gatewayProfile.GatewayID = Convert.ToInt64(dtRoute.Rows[0]["GatewayID"]);
                        gatewayProfile.SubmitterID = dtRoute.Rows[0]["SubmitterID"].ToString().Trim();
                        **gatewayProfile.ReceiverID = dtRoute.Rows[0]["ReceiverID"].ToString().Trim();**
                        gatewayProfile.AuthInfo = ReplaceDBNull(dtRoute.Rows[0]["AuthInfo"], "").Trim();
                        gatewayProfile.SecurityInfo = ReplaceDBNull(dtRoute.Rows[0]["SecurityInfo"], "").Trim();
                    }
                }

                return gatewayProfile;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally 
            {
                this.CloseConnection();
            }
        }

```

Third datatable

```
using (SqlCommand cmd = new SqlCommand())
{
    cmd.CommandText = "dbo.[stored procedure]";
    cmd.Connection = this.connection;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@param1", param1);
    cmd.Parameters.AddWithValue("@param2", param2);
    cmd.Parameters.AddWithValue("@param3", param3);
    cmd.Parameters.AddWithValue("@param4", param4);

    using (SqlDataAdapter sda = new SqlDataAdapter())
    {
        sda.SelectCommand = cmd;
        sda.Fill(dt);
    }
}

```

Thank you in advance if someone help me out to get this issue resolved.