Question: I have a WCF data service, which works fine. But now I want it to be able to use a different database based on a parameter that is sent by the consumer of my data service. 

Concrete example: a client from US that uses the data service passes 'US' as a parameter, and so the data service uses the US database. Another client from Belgium that uses the data service passes 'BE' as a parameter, so the data service uses the BE database. Of course all databases have same schemas.

Currently my client uses the data service like:

```
var qclient = new QueryServiceReference.Complaint_Entities(new Uri("http://localhost:60642/QueryService.svc"));

```

But how would it be possible to add a parameter to this? And how can I check this parameter in the data service?

So my question is: how to pass a parameter to a WCF data service?

EDIT: I found a way, but I don't know if it's the best method to do it. Before doing the request, I add the parameter to the request header:

```
 var qclient = new QueryServiceReference.Complaint_Entities(new Uri("http://localhost:60642/QueryService.svc"));
 qclient.SendingRequest += new EventHandler<System.Data.Services.Client.SendingRequestEventArgs>(qclient_SendingRequest);
 var cat = qclient.Categories.ToList();

static void qclient_SendingRequest(object sender, System.Data.Services.Client.SendingRequestEventArgs e)
{
   e.RequestHeaders.Add("Culture", "nl-BE");            
}

```

In the data service, I can then use it to set the connection string:

```
protected override Complaint_Entities CreateDataSource()
{
    var culture = HttpContext.Current.Request.Headers["Culture"];   
    // set connectionString based on culture
    return new Complaint_Entities(connectionString);    
}

```

Thanks,
L

Answer: 
Yes this is entirely possible. You can add a name to each connection string you have and then select that connectionstring based on a passed variable. 

//In your web.config

```
<connectionStrings>
    <add name="OracleDefault" connectionString="DATA SOURCE=G14DEV;PASSWORD=Password;USER ID=UserId; Provider=OraOLEDB.Oracle;" providerName="Oracle.DataAccess.Client"/>
    <add name="ApplicationDefault" connectionString="DATA SOURCE=G14DEV;PASSWORD=Password;USER ID=UserId; Provider=OraOLEDB.Oracle;" providerName="Oracle.DataAccess.Client"/>
<connectionStrings>

```

//In your code

```
public void Connect(string user)
{
    switch(user)
    {
        case "Default":
        {
            m_connectionString = ConfigurationManager.ConnectionStrings["ApplicationDefault"].ConnectionString;
            break;
        }
        case "Oracle":
        {
            m_connectionString = ConfigurationManager.ConnectionStrings["OracleDefault"].ConnectionString;

            break;
        }
    }

    //now connect to the database
}

```
That is fairly easy, all you have to do is to create a proper data context depending on the parameter value:

```
switch ( parameterValue ) {
   case "US" : datacontext = new ....( "US connectionstring" );
   case "EN" : datacontext = new ....( "BE connectionstring" );
}

```

However, there's a caveat and it's **authentication**. 

You have to design a mechanism to authenticate your requests so that it is impossible for US users to craft requests to BE database and vice versa.