Sql Server Custom code Issue in SSRS

Posted on 2009-04-20
Last Modified: 2012-05-06
Hi there:
  In the Code tab in Report Properties, I have the following code:

Function DBConnect() As System.Data.SqlClient.SqlConnection
        Dim connectionstring As String
        connectionstring = "server=lafap; database=astea8l; uid=re; pwd=v8;"  
        Dim cn As New System.Data.SqlClient.SqlConnection(connectionstring)
        Return cn
End Function

Function test() as String
    Dim cn As New System.Data.SqlClient.SqlConnection
    return "Connected"
END Function

Also , in the reference tab, I've referenced the System.Data.
in the layout, I put =code.test() into one of the table field. And SSRS gives me the following error:

The value expression for the textbox textbox4 contains an error: The ConnectionString property has not been initialized.

Does someone have any idea how to get rid of this error?
 Also any recommendations on the debug env. for Custom Code?

 Thanks a lot

Question by:HuiShi
    LVL 11

    Expert Comment

    by:N R
    Looks like it's not working because your not able to connect to the sql server.  Look here:
    LVL 26

    Accepted Solution

    Aren't you missing the call to your DBConnect() function?  maybe
    Dim cn As System.Data.SqlClient.SqlConnection
    cn = DBConnect()

    Author Closing Comment


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now