Pergunta

I've been developing an app which uses strongly typed datasets and stored procedures. I've just graduated and this was the method that was sold to us as the way to go. I'm starting to have severe doubts.

My client has advised me that he might change from SQL Server to MySQL. From what I've read it might be better to not use stored procedures as migrating could become more difficult. So anyhow I've just implemented a new table adapter query using the wizard and selected Use SQL Statements rather than Create new stored procedure.

My call to the query

Intranet.administratorsDataTable dt = taAdministrators.GetAdministrators();

now generates this error:

executereader requires an open and available connection. the connection's current state is closed

I have no idea why this auto generated code doesn't have a connection and I'm hungover and in no shape to deal with this. I decided to just go back to the SP's for the moment so I can get some work done. This error is still being thrown (same table adapter, same method name but reconfigured to use a SP). All of my other DB calls work fine.

I'm assuming the generated SQL code is still floating around somewhere even though I changed the adapter to use SP's. Can someone tell me where it is so I can delete it?

On another note I'm really starting to think that using SqlConnection and SqlCommand manually is a much better option, as using these query 'Tools' are just way to much trouble when it comes to flexibility such as modifying database tables etc. Can any of you more experienced people tell me if that's correct or do you advocate using table adapters?

*Edit it also throws these:

Invalid operation. The connection is closed.

and

There is already an open DataReader associated with this Command which must be closed first.

Foi útil?

Solução

The solution was to go to the query properties in the tableAdapter and manually change the "Command Type" to StoredProcedure.

highlight the query > go to properties window > change the command type

Seem this didn't (or doesn't) get auto updated when I reconfigure the query.

Outras dicas

if you provide some code, it would be better. I think, you need to open the the connection.

SqlCommand Cmd= new SqlCommand();
Cmd.Open();
// then u can use Cmd.ExecuteReader(); 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top