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.

You are viewing reply posted by: AnandM one year ago.
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>