Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 4 and Visual Studio 2010 > BOOK: Professional Visual Studio 2010
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Visual Studio 2010
This is the forum to discuss the Wrox book Professional Visual Studio 2010 by Nick Randolph, David Gardner, Chris Anderson, Michael Minutillo; ISBN: 9780470548653
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Visual Studio 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old March 28th, 2013, 12:49 PM
Authorized User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 30: Report Custom Code - SqlConnection - Unable to Open Database

I am unable to establish connection with my database through Custom Code. I have referenced to System.Data and System.Configuration and defined the assemblies permissions in the vb page code like this:
Imports Microsoft.Reporting.WebForms
Imports System.Reflection
Imports System.Security.Policy
Imports System.Security.Permissions

Partial Class Practice_Reports_Statistics
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Dim customAssemblyName As String = "TEStatistics, Version=, Culture=neutral, PublicKeyToken=1c14b99380c4e9b1"
        Dim customAssemblyName2 As String = "System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        Dim customAssemblyName3 As String = "System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        Dim customAssembly As Assembly = Assembly.Load(customAssemblyName)
        Dim customAssembly2 As Assembly = Assembly.Load(customAssemblyName2)
        Dim customAssembly3 As Assembly = Assembly.Load(customAssemblyName3)
        Dim assemblyStrongName As StrongName = CreateStrongName(customAssembly)
        Dim assemblyStrongName2 As StrongName = CreateStrongName(customAssembly2)
        Dim assemblyStrongName3 As StrongName = CreateStrongName(customAssembly3)
        Dim reportEngine As LocalReport = ReportViewer1.LocalReport

    End Sub
    Private Shared Function CreateStrongName(ByVal assembly As Assembly) As StrongName
        Dim assemblyName As AssemblyName = assembly.GetName()
        If assemblyName Is Nothing Then
            Throw New InvalidOperationException("Could not get assemmbly name")
        End If
        Dim publickey As Byte() = assemblyName.GetPublicKey()
        If publickey Is Nothing OrElse publickey.Length = 0 Then
            Throw New InvalidOperationException("Assembly is not strongly named")
        End If
        Dim keyblob As New StrongNamePublicKeyBlob(publickey)
        Return New StrongName(keyblob, assemblyName.Name, assemblyName.Version)

    End Function
End Class
Then in the Report Custom Code:
Public Shared Function TestFer() as string

        Dim myconnection As New System.Data.SqlClient.SqlConnection()
            myconnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString

            Dim myCommand As New System.Data.SqlClient.SqlCommand
            myCommand.Connection = myconnection
            myCommand.CommandText = "SELECT Classification FROM Accounts WHERE AccountID = @UserId"
myCommand.Parameters.AddWithValue("@UserId", 1)
dim msg as string = "Unable to open database"
Catch ex As Exception
return msg 

End Try
End Function
The report output textboxt then reads "Unable to open database". I'm still not able to connect to the database using the literal connection string.

Please Advise, Thanks!!

Last edited by fbuxo; March 28th, 2013 at 01:31 PM.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to open sample code downloaded williamgcl BOOK: Beginning Microsoft Visual Studio LightSwitch Development 0 August 17th, 2011 03:53 AM
Problem when SqlConnection.Open() hoetat C# 7 July 6th, 2008 08:43 PM
Report Manager - unable to open Reshmacb BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 October 23rd, 2007 03:22 AM
Unable to open report exported in Crystal rep jdaulagar Beginning VB 6 3 June 4th, 2007 09:06 AM
Access is unable to open database window amerk20 Access 1 April 21st, 2005 12:16 PM

All times are GMT -4. The time now is 02:35 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.