db connection in class library utility

Results 1 to 2 of 2

Thread: db connection in class library utility

  1. #1
    Join Date
    Dec 1969

    Default db connection in class library utility

    Hi I&#039;m trying to write a little utility to open a database connection to use to run queries against. I&#039;ve written a class library dll that has a simple function that sets the connection string and then opens the db. That all works fine. Back in my .net app I&#039;ve got a page that calls that connection utility. I&#039;m trying to keep this as simple as possible so when I need a db connect I just do &#039;utilities.opendb&#039; and then run my query. I know my app is reading this utility dll because other functions in it work fine. The problem I&#039;m having is that when I&#039;m executing a query it is not seeing an open connection and I get:<BR><BR>System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection&#039;s current state is Closed.<BR><BR><BR>This is what the code in .dll looks like:<BR>Public Function opendb()<BR><BR>Dim db As New SqlConnection("server=xxx;uid=xxxx;pwd=xxxxx;datab ase=xxxxx;connect timeout=500")<BR>db.Open()<BR><BR>End Function<BR><BR>This is what the code in page where it calls it looks like:<BR>utilities.opendb()<BR>cmdSQL = New SqlCommand("select * from tblVendors", db)<BR>rs = cmdSQL.ExecuteReader()

  2. #2
    Join Date
    Dec 1969

    Default RE: db connection in class library utility

    You need the utility class to return the open connection; your function doesn&#039;t return anything.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts