none
Modify Dataset's TableAdapters connection strings RRS feed

  • Question

  • Hi

    I would like to modify my dataset's table adapters connection string each time I am on the development machine and deploy on another machine.  For the time being, I am manually modifying each connection string for each table adapter every time i need to deploy.  Any advice of how to do it automatically?  Thanks.

    • Moved by Tina-Shi Friday, May 8, 2015 7:54 AM the issus is related to the ADO.NET DataSet
    Thursday, May 7, 2015 2:09 PM

Answers

  • Hello Rainbow man, 

    You make me curious, how does the installer automatically know if you don't support the name, type and place of your database where and what that is.

    You did not say it, but for the connectionstring is the configuration setting and the configuration manager, I was maybe wrong assuming that you where changing that everytime. 

    https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    Success
    Cor


    Monday, May 11, 2015 10:47 AM
  • Hello rainbow_man,

    >> Any advice of how to do it automatically?.

    I do not think the Visual Studio could help change it connecting string as it is a develop tool rather than a intelligent robot. My suggestion is that you could customize the DataSet:

    You could add an additional connectionstring property into the Settings class as:

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
    
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\Projects;Initial Catalog=ADO.NET;Integrated Security=True")]
    
            public string AutomaticConnectionString
    
            {
    
                get
    
                {
    
                    string automaticConnectionString;
    
                    //Check If it is a development machine
    
                    if (1 == 2)
    
                    {
    
                        automaticConnectionString = ((string)(this["ADO_NETConnectionString"]));
    
                    }
    
                    else
    
                    {
    
                        automaticConnectionString = ((string)(this["DFDBConnectionString"]));
    
                    }
    
                    return automaticConnectionString;
    
                }
    
            }
    
    
            [global::System.Configuration.ApplicationScopedSettingAttribute()]
    
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
    
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\Projects;Initial Catalog=ADO.NET;Integrated Security=True")]
    
            public string ADO_NETConnectionString
    
            {
    
                get
    
                {
    
                    return ((string)(this["ADO_NETConnectionString"]));
    
                }
    
            }
    
    
            [global::System.Configuration.UserScopedSettingAttribute()]
    
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\Projects;Initial Catalog=DFDB;Integrated Security=True;Conn" +
    
                "ect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=Read" +
    
                "Write;MultiSubnetFailover=False")]
    
            public string DFDBConnectionString
    
            {
    
                get
    
                {
    
                    return ((string)(this["DFDBConnectionString"]));
    
                }
    
                set
    
                {
    
                    this["DFDBConnectionString"] = value;
    
                }
    
            }
    

    Assuming the ADO_NETConnectionString to be the LAN connectionstring and the DFDBConnectionString to be your development connectionstring, you could add some logic as mine in the additional connectionstring property to select the one you need, and use this property when initializing the connection:

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
    
            private void InitConnection() {
    
                this._connection = new global::System.Data.SqlClient.SqlConnection();
    
                this._connection.ConnectionString = global::ADO.NET5.Properties.Settings.Default.AutomaticConnectionString;
    
            }
    

    Please take care that since these code is generated by templates according to the designer, it would be covered to be original as soon as saving the designer, you then need to modify them again.

    Regards.


    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.

    Monday, May 11, 2015 3:18 AM
    Moderator

All replies

  • Hi rainbow_man,

    Thank you for posting in MSDN forum.

    Since this issue is related to the ADO.NET DataSet, so we will move this case to this ADO.NET DataSet forum, you will get better support from this ADO.NET DataSet experts.

    Best Regards,


    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.

    Friday, May 8, 2015 7:54 AM
  • As long as your database is in the same LAN the connectionstring does not change.


    Success
    Cor

    Saturday, May 9, 2015 10:06 AM
  • Thanks for reply.  At the moment, it is deployed on same LAN for testing but will also be deployed on client machine.  Should I modify the connection programatically as some are saying, or is there a way in VS2010 to do that automatically?


    Saturday, May 9, 2015 3:29 PM
  • Hello rainbow_man,

    >> Any advice of how to do it automatically?.

    I do not think the Visual Studio could help change it connecting string as it is a develop tool rather than a intelligent robot. My suggestion is that you could customize the DataSet:

    You could add an additional connectionstring property into the Settings class as:

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
    
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\Projects;Initial Catalog=ADO.NET;Integrated Security=True")]
    
            public string AutomaticConnectionString
    
            {
    
                get
    
                {
    
                    string automaticConnectionString;
    
                    //Check If it is a development machine
    
                    if (1 == 2)
    
                    {
    
                        automaticConnectionString = ((string)(this["ADO_NETConnectionString"]));
    
                    }
    
                    else
    
                    {
    
                        automaticConnectionString = ((string)(this["DFDBConnectionString"]));
    
                    }
    
                    return automaticConnectionString;
    
                }
    
            }
    
    
            [global::System.Configuration.ApplicationScopedSettingAttribute()]
    
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
    
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\Projects;Initial Catalog=ADO.NET;Integrated Security=True")]
    
            public string ADO_NETConnectionString
    
            {
    
                get
    
                {
    
                    return ((string)(this["ADO_NETConnectionString"]));
    
                }
    
            }
    
    
            [global::System.Configuration.UserScopedSettingAttribute()]
    
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\Projects;Initial Catalog=DFDB;Integrated Security=True;Conn" +
    
                "ect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=Read" +
    
                "Write;MultiSubnetFailover=False")]
    
            public string DFDBConnectionString
    
            {
    
                get
    
                {
    
                    return ((string)(this["DFDBConnectionString"]));
    
                }
    
                set
    
                {
    
                    this["DFDBConnectionString"] = value;
    
                }
    
            }
    

    Assuming the ADO_NETConnectionString to be the LAN connectionstring and the DFDBConnectionString to be your development connectionstring, you could add some logic as mine in the additional connectionstring property to select the one you need, and use this property when initializing the connection:

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
    
            private void InitConnection() {
    
                this._connection = new global::System.Data.SqlClient.SqlConnection();
    
                this._connection.ConnectionString = global::ADO.NET5.Properties.Settings.Default.AutomaticConnectionString;
    
            }
    

    Please take care that since these code is generated by templates according to the designer, it would be covered to be original as soon as saving the designer, you then need to modify them again.

    Regards.


    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.

    Monday, May 11, 2015 3:18 AM
    Moderator
  • Hello Rainbow man, 

    You make me curious, how does the installer automatically know if you don't support the name, type and place of your database where and what that is.

    You did not say it, but for the connectionstring is the configuration setting and the configuration manager, I was maybe wrong assuming that you where changing that everytime. 

    https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    Success
    Cor


    Monday, May 11, 2015 10:47 AM