?
Solved

Visual Basic - connecting to SQL Server:  overcoming an unhandled exception occurred.

Posted on 2014-04-23
1
Medium Priority
?
295 Views
Last Modified: 2014-04-23
The following code is failing me on line:  _sqlconnection.Open()

Public Function GetTables() As DataSet
        _sqlconnection = New SqlConnection(ConfigurationManager.ConnectionStrings(BlockConStr))
        Dim ds As DataSet = New DataSet()

        Try
            Dim cmd As SqlCommand = New SqlCommand()
            cmd.CommandText = "GetBlockandFiles"
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = _sqlconnection
            If _sqlconnection.State = ConnectionState.Closed Then
                _sqlconnection.Open()
            End If
            Dim _sqladapter As SqlDataAdapter = New SqlDataAdapter(cmd)


            _sqladapter.Fill(ds)
            _sqlconnection.Close()
        Catch ex As Exception
            MessageBox.Show("An Unhandled exception occured : " + ex.Message.ToString())
        End Try
        Return ds

    End Function

Open in new window


here is the function for BlockConStr:

    Public Function BlockConStr()
        'Return "Server=.;Database=BlocksCycle; User Id=sa;Pwd=123456;connection timeout = 1"
        Return "Server=10.0.1.72\SQLEXPRESS;Database=BlocksCycle;User Id=BlocksCycle;Pwd=bl0ckCycle;connection timeout = 1"
    End Function

Open in new window


I'm interested in getting exact code in order to overcome the following error:

An Unhandled exception occurred:  The ConnectionString property has not been initialized.  (please note error attachment)

This was originally working through app.config file and was told I need to avoid using that since the end result is a plugin.

Thank you in advanced.
error.PNG
0
Comment
Question by:stephenlecomptejr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 40019053
you are not using a config file.

replace:
_sqlconnection = New SqlConnection(ConfigurationManager.ConnectionStrings(BlockConStr)

with:
_sqlconnection = New SqlConnection(BlockConStr)
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question