Error: System.NullReferenceException Object reference not set to an instance of an object when connection string not defined in ASP.Net

kennr
 
on Jan 29, 2017 09:31 PM
3254 Views

Hello.  I am requesting assistance to actually run the examples shown at http://www.aspsnippets.com/Articles/Retrieve-and-display-PDF-Files-from-database-in-browser-in-ASPNet.aspx .

My code is supposed to ASP.NET, VB.NET compliant.

My situation is almost exactly the same as the example there.  Need to upload some (.pdf) files (say smaller than 100kB each), then store each in varbinary(max?) field in SQL Server 2008 R2 database, then make them available for viewing later in HTML Browser (preferably each in its own page).

When I tried to actually run the html provided, I got the following error:

Compiler Error Message: BC30456: 'Upload' is not a member of 'ASP.pdf_sql_server_aspx'.

Source Error:

Line 17: <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />

Appreciate any help provided.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Andrea
 
on Jan 29, 2017 09:31 PM
Hi @kennr,
Please try the following

Need some example on how group by clause works in SQL Server

It might help you.

Cheers Andrea.
kennr
 
on Jan 29, 2017 09:41 PM
on Jan 29, 2017 09:51 PM

I appreciate the quick response but this reply is not quite what I needed.  To start I need help getting the HTML example code to work.

 

kennr
 
on Jan 29, 2017 10:36 PM
on Jan 29, 2017 11:22 PM

An Update:

After download from http://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=df4e1964-2677-490a-926a-468cb4bf959b.zip .

After Build in VS2010, I viewed (ran) the VB.aspx file in Browser.  I got the following compiler error in VB.aspx.vb:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 13:     End Sub
Line 14:     Private Sub BindGrid()
Line 15:         Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Line 16:         Using con As New SqlConnection(constr)
Line 17:             Using cmd As New SqlCommand()


Source File: C:\...\VB.aspx.vb    Line: 15

Your helps are prreciated.

 

 

AnandM
 
on Jan 30, 2017 04:59 AM
kennr says:
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString

 You need to set the connection string in configuration section of your web.config like below

<connectionStrings>
    <add name ="constr" connectionString="Server=xxxxx;DataBase=Test;UID=xxx;PWD=xxxx" providerName="System.Data.SqlClient" />
</connectionStrings>