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. General Programming
  3. C#
  4. SQL Problem.

SQL Problem.

Scheduled Pinned Locked Moved C#
csharphelpdatabasesql-serversysadmin
5 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.
  • J Offline
    J Offline
    Janu_M
    wrote on last edited by
    #1

    Hi, I am developing a C# windows application(.net 2003). The functionality of this application is to import all the records from a csv file to a table in a SQL Server 2000. For this i am opening a sql connection and I am using Sql command. Here i set sqlcommand timeout to 500. I am using a for loop to insert each record into sql table. After finishing all records i am closing and disposing sql connection. This is working fine. For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data. For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500. After fetching data i am disposing that sql connection. This funtion is called for each record in the csv file. After inserting approximately 200 records it is giving an Exception Message "Timeout Expired. The timeout period elapsed prior to obtaining a connection form the pool. This may have occured because all pooled connections were in use and max pool size was reached". How to overcome this problem. It's urgent Any one please help me. Thanks in Advance. Ramu

    N A 2 Replies Last reply
    0
    • J Janu_M

      Hi, I am developing a C# windows application(.net 2003). The functionality of this application is to import all the records from a csv file to a table in a SQL Server 2000. For this i am opening a sql connection and I am using Sql command. Here i set sqlcommand timeout to 500. I am using a for loop to insert each record into sql table. After finishing all records i am closing and disposing sql connection. This is working fine. For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data. For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500. After fetching data i am disposing that sql connection. This funtion is called for each record in the csv file. After inserting approximately 200 records it is giving an Exception Message "Timeout Expired. The timeout period elapsed prior to obtaining a connection form the pool. This may have occured because all pooled connections were in use and max pool size was reached". How to overcome this problem. It's urgent Any one please help me. Thanks in Advance. Ramu

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Ramu.M wrote:

      For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data. For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500.

      Are you using stored procedures ? If yes then you can get this primary value through an output variable. This will avoid creating connection again.

      Ramu.M wrote:

      After inserting approximately 200 records it is giving an Exception Message

      Verify your code to find how many instances of SQLConnection will be open when it reaches 200 ? Try to reduce the number of connection objects open. Make sure that all SQLConnection instances are returned back to pool. How you are disposing the objects ?

      SqlConObject.Open()
      //Do operation
      SqlConObject.Close()
      SqlConObject.Dispose()

      Above code will keep the connection in opened state when any error happens on do operations. So it's better to wrap the connection in between using statements. This will dispose object even though any error happens.

      using (SqlConObject)
      {
      //Do operation
      SqlConObject.Close()
      }


      My Website | Ask smart questions

      J 1 Reply Last reply
      0
      • J Janu_M

        Hi, I am developing a C# windows application(.net 2003). The functionality of this application is to import all the records from a csv file to a table in a SQL Server 2000. For this i am opening a sql connection and I am using Sql command. Here i set sqlcommand timeout to 500. I am using a for loop to insert each record into sql table. After finishing all records i am closing and disposing sql connection. This is working fine. For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data. For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500. After fetching data i am disposing that sql connection. This funtion is called for each record in the csv file. After inserting approximately 200 records it is giving an Exception Message "Timeout Expired. The timeout period elapsed prior to obtaining a connection form the pool. This may have occured because all pooled connections were in use and max pool size was reached". How to overcome this problem. It's urgent Any one please help me. Thanks in Advance. Ramu

        A Offline
        A Offline
        Andrei Ungureanu
        wrote on last edited by
        #3

        Hy, Have you tried creating a buffer or such? I mean to create a list with your queries first. When you insert a new query to the list you call the function to get the UID and then fetch the data from the CSV file and then create the query. After you have finished creating the query list just open a connection to the server and loop inside the list to insert the data. Hope it helps

        Do your best to be the best

        J 1 Reply Last reply
        0
        • N N a v a n e e t h

          Ramu.M wrote:

          For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data. For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500.

          Are you using stored procedures ? If yes then you can get this primary value through an output variable. This will avoid creating connection again.

          Ramu.M wrote:

          After inserting approximately 200 records it is giving an Exception Message

          Verify your code to find how many instances of SQLConnection will be open when it reaches 200 ? Try to reduce the number of connection objects open. Make sure that all SQLConnection instances are returned back to pool. How you are disposing the objects ?

          SqlConObject.Open()
          //Do operation
          SqlConObject.Close()
          SqlConObject.Dispose()

          Above code will keep the connection in opened state when any error happens on do operations. So it's better to wrap the connection in between using statements. This will dispose object even though any error happens.

          using (SqlConObject)
          {
          //Do operation
          SqlConObject.Close()
          }


          My Website | Ask smart questions

          J Offline
          J Offline
          Janu_M
          wrote on last edited by
          #4

          Thank Q

          1 Reply Last reply
          0
          • A Andrei Ungureanu

            Hy, Have you tried creating a buffer or such? I mean to create a list with your queries first. When you insert a new query to the list you call the function to get the UID and then fetch the data from the CSV file and then create the query. After you have finished creating the query list just open a connection to the server and loop inside the list to insert the data. Hope it helps

            Do your best to be the best

            J Offline
            J Offline
            Janu_M
            wrote on last edited by
            #5

            Thank Q

            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