connection class

May 31 2004 7:47 AM
I've written a connection class to use in all my files: [code] using System; using System.Web; using System.Web.UI; using System.Data; using System.Data.SqlClient; public class DataBaseConnection : Page { public SqlConnection connection; public SqlConnection conn() { connection = new SqlConnection(); connection.ConnectionString = "Trusted_Connection = yes; initial catalog=''; data source=''; Connect Timeout=30 "; connection.Open(); return connection; } } [/code] That is how I import it to my .aspx files: [code] <%@Page Inherits="DataBaseConnection" Src="Connection.cs"%> <%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.SqlClient"%> [/code] This code is supposed to view the table called "Banks". It worked fine before when I wrote the code of connection in the file. Now, I get this error: [code] Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized Line 156: reader = command.ExecuteReader(); [/code] Anything? Thank you.

Answers (1)

1
Tanvir Huda

Tanvir Huda

  • 0
  • 226
  • 0
Jun 1 2004 12:43 AM
Yap that is a quite a valid error . Though u have inherited the Connection.cs file. But u have not explicitrly called its conn method. I mean DataBaseConnection .Conn().. Create an instance of DataBaseConnection and then call Conn.. like the following DataBaseConnection dc= new DataBaseConnection (); SqlConnection conn=dc.conn(); I think this will work.. Good Luck