Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Showing User Control Connection initialize error
 

Showing User Control Connection initialize error

Dear Experts,
I have created a user control (use a combobox only)
Code is as follows:
------------------------
Public Class Company
Public Event ComID(ByVal Com As Object)
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCompany.SelectedIndexChanged
RaiseEvent ComID(cmbCompany.SelectedValue)
End Sub
Private Sub CallCom(ByVal SQL As String)
Try
Dim ds As DataSet = New DataSet
Dim da As New SqlClient.SqlDataAdapter(SQL, Cn)
da.SelectCommand.CommandType = CommandType.Text
da.Fill(ds, "ComID")
cmbCompany.DataSource = ds.Tables("ComID")
cmbCompany.DisplayMember = "Name"
cmbCompany.ValueMember = "CompanyCode"
Catch exSQL As SqlClient.SqlException
MessageBox.Show(exSQL.Message())
Finally

End Try
End Sub
Private Sub Company_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call CallCom("select CompanyCode,Name from MtCM where del='0' order by CompanyCode")
End Sub
End Class

Problem
------------
When I am dragging control on form it is showing error (snapshot attached).

As it is showing connection string initializing error: I am providing below connection string for review:

Module Module1
Public Cn As New System.Data.SqlClient.SqlConnection

Sub main()
Try
'Cn = New System.Data.SqlClient.SqlConnection
Cn.ConnectionString = "password=jazzciti;Persist Security Info=True;User ID=sa;Initial Catalog=OILDB;Data Source=Mehram\SQLExpress"
Cn.Open()
If Cn.State = ConnectionState.Open Then
Application.Run(New frmUser)
End If
Catch exsql As SqlClient.SqlException
MessageBox.Show(exsql.Message())
Finally
Cn.Dispose()
End Try
End Sub
End Module


Please help
IM

Iqbal Mehram  Friday, September 11, 2009 3:22 AM

Hi Iqbal,

From my experience, the root cause of your issue is that some code about database is executed in design-time. We can only execute code about database in runtime.

To solve this issue, we need to check the DesignMode property to ignore the code about database in design-time. This is an example:

    Private Sub Company_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not DesignMode Then
            'Execute code only in runtime.
            Call CallCom("select CompanyCode,Name from MtCM where del='0' order by CompanyCode")
        End If
    End Sub


Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer byIqbal Mehram Thursday, September 17, 2009 6:03 AM
  •  
Aland Li  Tuesday, September 15, 2009 7:36 AM

Hi Iqbal,

From my experience, the root cause of your issue is that some code about database is executed in design-time. We can only execute code about database in runtime.

To solve this issue, we need to check the DesignMode property to ignore the code about database in design-time. This is an example:

    Private Sub Company_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not DesignMode Then
            'Execute code only in runtime.
            Call CallCom("select CompanyCode,Name from MtCM where del='0' order by CompanyCode")
        End If
    End Sub


Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer byIqbal Mehram Thursday, September 17, 2009 6:03 AM
  •  
Aland Li  Tuesday, September 15, 2009 7:36 AM

Hi Iqbal,

From my experience, the root cause of your issue is that some code about database is executed in design-time. We can only execute code about database in runtime.

To solve this issue, we need to check the DesignMode property to ignore the code about database in design-time. This is an example:

    Private Sub Company_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not DesignMode Then

            'Execute code only in runtime.

            Call CallCom("select CompanyCode,Name from MtCM where del='0' order by CompanyCode")

        End If

    End Sub

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.

Its Great
Iqbal Mehram  Thursday, September 17, 2009 6:34 AM
Hi Iqbal Mehram,

You are welcome.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, September 17, 2009 6:35 AM
Sir, I am new in Dot Net. Can you give me a favor?
I want to creat reports and some times reports with sub reports.
Is there any link or side which can help me to build report?
Iqbal Mehram  Thursday, September 17, 2009 6:45 AM
Hi Iqbal Mehram,

You can use Crystal Report: Iqbal Mehram: http://www.codeproject.com/KB/dotnet/CrystalWin.aspx.

Please post new question in a new thread.

Regards,
Aland Li

This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, September 17, 2009 6:53 AM

You can use google to search for other answers

Custom Search

More Threads

• SplitterPanel delete - or how can I disable the delete command for a specific component
• Weird behavior when customizing property grid.
• Windows Forms Designer Instablility
• Child components in design time
• Custom UITypeEditor and the PropertyGrid
• Locking the resizing of an user control
• populating treeview control with directories - SLOW
• 2 WinForm bugs
• how can i stop the IDE from being so "helpful?"
• Pb: attribute with an "object" argument and the designer