none
[BC30201] Expression expected ssrs

    Question

  • hi,

    I am getting an error in my code as Expression expected

    code:

    Function westsubsum() As decimal

    Dim conn As New System.Data.SqlClient.SqlConnection

            conn.ConnectionString =

                  "Data Source=asharaf;" +

                  "Initial Catalog=test;" +

                  "Integrated Security=SSPI;"

            conn.Open()

            Dim Cmd As New System.Data.SqlClient.SqlCommand

            Cmd.Connection = conn

            Cmd.CommandText = "select dbo.calculatesumwithdate(1000000,2000000,'12/31/2008')"

            Dim totval As Decimal = Cmd.ExecuteScalar()

            conn.Close()

    return totval

    end function

    Thursday, January 17, 2013 6:19 PM

Answers

All replies

  • Please can you share the exact error.
    Thursday, January 17, 2013 6:29 PM
  • hi,

    Thanks for your reply.

    I found that error.

    i was missed the barces after the connection string.

    Function westsubsum() As decimal

    Dim conn As New System.Data.SqlClient.SqlConnection(conn.ConnectionString ="Data Source=asharaf;" +"Initial Catalog=test;" + "Integrated security=SSPI;")

            conn.Open()

            Dim Cmd As New System.Data.SqlClient.SqlCommand

            Cmd.Connection = conn

            Cmd.CommandText = "select dbo.calculatesumwithdate(1000000,2000000,'12/31/2008')"

            Dim totval As Decimal = Cmd.ExecuteScalar()

            conn.Close()

    return totval

    end function

    i successfully run my code but i am gettong #error in my text field.

    Thursday, January 17, 2013 6:32 PM
  • Hi,

    I am writing a code in custom code to access the sql data.

    Function westsubsum() As decimal
    Dim conn As New System.Data.SqlClient.SqlConnection ("Data Source=asharaf;Initial Catalog=test;Integrated Security=true")
            conn.Open()
            Dim Cmd As New System.Data.SqlClient.SqlCommand
            Cmd.Connection = conn
            Cmd.CommandText = "select dbo.calculatesumwithdate(1000000,2000000,'12/31/2008')"
            Dim totval As Decimal = Cmd.ExecuteScalar()
            conn.Close()
     return totval
    end function 

    i calles in expression as =code.westsubsum

    i m getting #error in my expression

    Thursday, January 17, 2013 7:14 PM
  • Dim conn As New System.Data.SqlClient.SqlConnection ("Data Source=asharaf;Initial Catalog=test;Integrated Security=true")
    ....
    Dim totval As Decimal = Cmd.ExecuteScalar()

    Hello Asharaf,

    I see 2 possible reasons for the error:

    - The connection is made with the current Windows account (Integrated Security=true). If the report is executed in SSRS, then the SSRS service account would be the current Windows account; do this account have permissions to logon to SQL Server and to query the data?

    - Does the function really return a decimal value? Otherwise it could be a cast exception.

    You can use a TRY/CATCH block to get detailed information about the error cause; see Error Handling in Visual Basic .NET


    Olaf Helper

    Blog Xing

    Thursday, January 17, 2013 7:43 PM
  • Hi,

    i am getting this error

    Cannot find either column "dbo" or the user-defined function

    Friday, January 18, 2013 8:29 AM
  • Hi Asharaf,

    Please ensure that you have already added the reference for the custom code.
    Go to->Report Properties ->References->Add->select System.Data dll from the pop-up window and you will get like below:
    System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

    Besides, you should elevated privileges to access protected resources for the custom code. Here has a thread that is similar to yours, please see:
    http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/129da450-58fa-439d-9a3e-44e8f5ac44b4

    Hope this helps.

    Regards,
    Charlie Liao


    Charlie Liao
    TechNet Community Support

    Wednesday, January 23, 2013 9:42 AM
    Moderator