1

I have a class like this:

class connect:IDisposable { public void OpenChannel(SqlConnection ch) { ch.ConnectionString="....."; ch.Open(); } public void Dispose() { } } 

And another class like this:

public Cust { SqlConnection channel=new SqlConnection(); SqlCommand command=new SqlCommand(); public void Method() { using(connect con=new connect()) { con.OpenChannel(channel); command.connection=channel; ..... .... .... command.ExecuteNonQuery(); } } 

But when I run ExcuteNotQuery() there is an error: "no open connection" So what is wrong?

5
  • Not technically wrong, but connect should start with a capital C. Commented Aug 6, 2011 at 15:59
  • it would help if you posted a working example that shows the problem extracted from the real code Commented Aug 6, 2011 at 16:03
  • 1
    This code won't even compile - so it's possible you've mis-transcribed the bug anyway... can you paste extracts from the actual code? Commented Aug 6, 2011 at 16:03
  • yeah the 'class' keyword is missing but it shouldn't compile without it. Commented Aug 6, 2011 at 16:04
  • On a design level - presumably Cust is a customer - not sure that a customer style entity usually has it's own connection/command fields. Unrelated to the issue - I'm just saying... Commented Aug 6, 2011 at 16:06

1 Answer 1

3
public Cust { SqlConnection channel=new SqlConnection(); SqlCommand command;//=new SqlCommand(); public void Method() { using(connect con=new connect()) { con.OpenChannel(channel); //command.connection=channel; // create command from open connection command = channel.CreateCommand(); ..... .... .... command.ExecuteNonQuery(); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.