locked
Modify connectionString dynamically in WCF Data Services 5.6 RRS feed

  • Question

  •  I'm using Oracle DataAccess (the last one), I have many Database users inside it. So, I want to create the connectionString in my client application (WPF) and pass it to the server.

    I'm doing the following in my server:  

    protected override POSContext CreateDataSource()
    {
        HttpRequest req = HttpContext.Current.Request;
    
        if (req.Headers != null && Array.FindIndex(req.Headers.AllKeys, c=>c.Equals("db", StringComparison.OrdinalIgnoreCase)) > 0)
        {
            string database = req.Headers["db"]; 
            string user = req.Headers["user"];
            string pass = req.Headers["pass"];
    
            StringBuilder conexion = new StringBuilder();
            conexion.Append("DATA SOURCE=");
            conexion.Append(database);
            conexion.Append(";USER ID=");
            conexion.Append(user);
            conexion.Append(";PASSWORD=");
            conexion.Append(pass);
    
            if (!string.IsNullOrEmpty(conexion.ToString()))
                return new POSContext(conexion.ToString());
        }
        return null;//new POSContext();
    }

    In the client, I have the following code:

    var context = new POS.DataServices.POSContext(new Uri(Storage.Current.UrlService)); // Something like this http://localhost/POService.svc
        context.BuildingRequest += (s, args) => //Or SendingRequest2 produces the same result
        {
            args.Headers.Add("db", Storage.Current.Configuraciones.DB);
            args.Headers.Add("user", Storage.Current.Configuraciones.UserName);
            args.Headers.Add("pass", Storage.Current.Configuraciones.Password);
        };
        MessageBox.Show(proxy.POS_CIUDAD.ToList().FirstOrDefault().CIU_DESC); //Alert the city name

    When I debug my application I have an error (request error). My client code is trying to Show the message first and then go to the BuildingRequest. How can I pass the connectionString before Entity calls?

    Thanks in advance.

          

    Christian Amado
    Software Engineer | MCPD: Windows Phone Developer | MCTS: Silverlight Developer
    Don't forget to mark the right answer and vote up if helps you.
    MCP Profile

    Wednesday, January 7, 2015 7:33 PM

All replies

  • Hi Christian Amado,

    I will move your thread to WCF Data Services forum for better support.

    Thanks for your understanding.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, January 8, 2015 7:00 AM