Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. plz help... connection problem to sql server 2000

plz help... connection problem to sql server 2000

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharpasp-netsql-server
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haseeb_saeed
    wrote on last edited by
    #1

    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

    P S 2 Replies Last reply
    0
    • H haseeb_saeed

      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

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      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.

      H 1 Reply Last reply
      0
      • H haseeb_saeed

        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

        S Offline
        S Offline
        Shaik Haneef
        wrote on last edited by
        #3

        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.............................................................

        1 Reply Last reply
        0
        • P Paddy Boyd

          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.

          H Offline
          H Offline
          haseeb_saeed
          wrote on last edited by
          #4

          thanx... That was really stupid of me .. right? i dont know how i missed on this point... Thankyou very much...

          haseeb

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups