Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-04-23
1
Medium Priority
?
296 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

610 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