plz help... connection problem to sql server 2000
-
hello... i have made windows app before and now am making my first web app in asp.net and cant figure out why my database connection won't open for the executenonquery method whereas it works fine with executereader method... i have tried debuggin it and the only error that i find is that in the connection object ... there is an exception of invalid server version... (wat is it or why is it.. i have no idea)... the code for the execute query method is public static int ExecuteNonQueryCommand(string sqlProcName, params IDataParameter[] procParameters) { SqlCommand command = null; try { command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = sqlProcName; if (procParameters != null) for (int index = 0; index < procParameters.Length; index++) command.Parameters.Add(procParameters[index]); Connection.Open(); // a getter property that returns //connection made from the web.config connectionstring property //the connection doesnt' open...some error with the server version command.Connection = Connection; return command.ExecuteNonQuery(); } catch { return 0; } finally { if (command != null) command.Dispose(); procParameters = null; Connection.Close(); } I have made a property that returns a connection as return new sqlConnection(configurationmanager....)) /// if this is a bad approach .. plz lemme know why it is so and what should i do.. . i call this method by passing the procedure name and parameters.. Plz help
haseeb
-
hello... i have made windows app before and now am making my first web app in asp.net and cant figure out why my database connection won't open for the executenonquery method whereas it works fine with executereader method... i have tried debuggin it and the only error that i find is that in the connection object ... there is an exception of invalid server version... (wat is it or why is it.. i have no idea)... the code for the execute query method is public static int ExecuteNonQueryCommand(string sqlProcName, params IDataParameter[] procParameters) { SqlCommand command = null; try { command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = sqlProcName; if (procParameters != null) for (int index = 0; index < procParameters.Length; index++) command.Parameters.Add(procParameters[index]); Connection.Open(); // a getter property that returns //connection made from the web.config connectionstring property //the connection doesnt' open...some error with the server version command.Connection = Connection; return command.ExecuteNonQuery(); } catch { return 0; } finally { if (command != null) command.Dispose(); procParameters = null; Connection.Close(); } I have made a property that returns a connection as return new sqlConnection(configurationmanager....)) /// if this is a bad approach .. plz lemme know why it is so and what should i do.. . i call this method by passing the procedure name and parameters.. Plz help
haseeb
Every time you call the property, it will return a new SqlConnection object, so your call to Open() here is on one connection object, but the object you pass to the command is a different one.
-
hello... i have made windows app before and now am making my first web app in asp.net and cant figure out why my database connection won't open for the executenonquery method whereas it works fine with executereader method... i have tried debuggin it and the only error that i find is that in the connection object ... there is an exception of invalid server version... (wat is it or why is it.. i have no idea)... the code for the execute query method is public static int ExecuteNonQueryCommand(string sqlProcName, params IDataParameter[] procParameters) { SqlCommand command = null; try { command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = sqlProcName; if (procParameters != null) for (int index = 0; index < procParameters.Length; index++) command.Parameters.Add(procParameters[index]); Connection.Open(); // a getter property that returns //connection made from the web.config connectionstring property //the connection doesnt' open...some error with the server version command.Connection = Connection; return command.ExecuteNonQuery(); } catch { return 0; } finally { if (command != null) command.Dispose(); procParameters = null; Connection.Close(); } I have made a property that returns a connection as return new sqlConnection(configurationmanager....)) /// if this is a bad approach .. plz lemme know why it is so and what should i do.. . i call this method by passing the procedure name and parameters.. Plz help
haseeb
SqlConnection Connection= new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["yourconnection"].ToString()); Connection.open(); you forgot to add this line, even though u declare connection string in web.config u need to call the connection form web.config System.Configuration.ConfigurationManager.AppSettings["yourconnection"].ToString() by using this line; yourconnection replace with your connection string name Regards, Shaik Haneef for more doubts conttact : sk.haneef@gmail.com
This is haneef.............................................................
-
Every time you call the property, it will return a new SqlConnection object, so your call to Open() here is on one connection object, but the object you pass to the command is a different one.
thanx... That was really stupid of me .. right? i dont know how i missed on this point... Thankyou very much...
haseeb