Solved

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

Posted on 2014-04-23
1
288 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
1 Comment
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

828 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