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

Last Reply one year ago By AnandM

Posted one year ago

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.

Posted one year ago
Hi @kennr,
Please try the following

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

It might help you.

Cheers Andrea.

Posted one year ago Modified on one year ago

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.

 


Posted one year ago Modified on one year ago

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.

 

 


Posted one year ago
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>