Sql Server Custom code Issue in SSRS

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

Who is Participating?
Chris LuttrellConnect With a Mentor Senior Database ArchitectCommented:
Aren't you missing the call to your DBConnect() function?  maybe
Dim cn As System.Data.SqlClient.SqlConnection
cn = DBConnect()
Nathan RileyFounderCommented:
Looks like it's not working because your not able to connect to the sql server.  Look here:

HuiShiAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.