Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a component that link in database so should have a Connection property as follow :
C#
private string constr;
private SqlConnection con;
...
...
[RefreshProperties(RefreshProperties.All),
DefaultValue(""),
Editor("Microsoft.VSDesigner.Data.SQL.Design.SqlConnectionStringEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
            "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
    ]

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public string ConnectionString
    {
        get
        {
            return constr;
        }
        set
        {
            constr = value;
            if (!this.DesignMode)
            {
                if (con.State != ConnectionState.Closed)
                    con.Close();
                con.ConnectionString = constr;
                if (!this.DesignMode)
                    con.Open();
            }
        }
 }

now when I use this component every thing is good but when I open connection property combobox in design time only connectionstring that set in server explorer window shown but I need to choose connectin string that set in app.config but this does not show . anybody can tell me how add connection string in app.config in my property combobox . thanks
Posted
Comments
dan!sh 30-Jan-13 3:00am    
Where are you setting the ConnectionString property?

1 solution

C#
public static List<string> ReadAppSettings()
{
  List<string> list = new List<string>();
  // Get the AppSettings section.
  ConnectionStringSettingsCollection connections =
               ConfigurationManager.ConnectionStrings;

  if (connections.Count != 0)
  {
    Console.WriteLine();
    Console.WriteLine("Using ConnectionStrings property.");
    Console.WriteLine("Connection strings:");
    // Get the collection elements. 
    foreach (ConnectionStringSettings connection in 
      connections)
    {
      list.Add(connection.Name);
    }
    return list;
  }
   else
  {
    Console.WriteLine();
    Console.WriteLine("No connection string is defined.");
    Console.WriteLine();
  }
}


Use this list as datasource to your combobox.
After selecting a value from combobox, get Value for Selected DB key.
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900