Microsoft Knowledge Base Email Alertz

KBAlertz.com: (329247) - When you debug, you receive the following error message if you step over the SqlConnection.Open function in a Timer event: There is no source code for the current location.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 329247 - Last Review: May 18, 2007 - Revision: 3.5

BUG: You cannot open a SQLConnection in a Timer event when you debug in Visual Studio

This article was previously published under Q329247

On This Page

SYMPTOMS

When you debug, you receive the following error message if you step over the SqlConnection.Open function in a Timer event:
There is no source code available for the current location.

WORKAROUND

To work around this behavior, use the Timer component that the System.Timers namespace provides. The Timer component is a server-based timer. The Timer component permits you to specify a recurring interval where the Elapsed event is raised in your application. You can then handle this event to provide regular processing.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual Basic Projects under Project Types, and then click Windows Application under Templates.
  4. Name the project MySqlApplication, and then click OK.
  5. In the Code View window of Form1, replace the existing code with the following code:
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    #Region " Windows Form Designer generated code "
    
        Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
    
        End Sub
    
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents Timer1 As System.Windows.Forms.Timer
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container()
            Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
            '
            'Timer1
            '
            Me.Timer1.Enabled = True
            Me.Timer1.Interval = 500
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 266)
            Me.Name = "Form1"
            Me.Text = "Form1"
    
        End Sub
    
    #End Region
        Public Sub CreateSqlConnection()
            Dim myConnection As New SqlClient.SqlConnection()
    							
    							'replace the connection string with the your connection string to SQL Server
            myConnection.ConnectionString = "Data Source=myserver;Integrated Security=SSPI;Initial Catalog=northwind"
            
            ' Opens a database connection with the property settings specified by the ConnectionString.
            myConnection.Open()
          
           ' Closes the connection to the database.
            myConnection.Close()
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Enabled = False
            CreateSqlConnection()
        End Sub
    End Class
    
  6. Add a breakpoint at CreateSqlConnection in the Timer1_Tick event procedure.
  7. Press F5 to debug the project. Program execution breaks at breakpoint.
  8. Press F11 to step into the CreateSqlConnection event procedure.
  9. Press F10 until you reach myConnection.Open().
  10. Press F10. You receive the error message that is mentioned in the "Symptoms" section.

REFERENCES

For more information about the Timer class, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/system.timers.timer(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.timers.timer(vs.71).aspx)

APPLIES TO
  • Microsoft ADO.NET 2.0
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
Keywords: 
kbtshoot kberrmsg kbvs2002sp1sweep kbtimer kbbug kbdebug KB329247
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please