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. Regarding SQL Database

Regarding SQL Database

Scheduled Pinned Locked Moved C#
databasecsharpsysadmin
7 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.
  • M Offline
    M Offline
    manojk_batra
    wrote on last edited by
    #1

    Dear All, I know this section is regarding C# only,but I am entering regarding SQL Database. I am really sorry for this. I want to Delete the SQL Database programmatically (using C#). I am using following code for Deleting Database. ---------------------------------------------------------- private void DeleteDatabase() { try { String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";"; SqlConnection sqc = new SqlConnection(conn); sqc.Open(); SqlCommand sc = new SqlCommand(); sc.Connection = sqc; sc.CommandText = "DROP DATABASE "+strDatabaseName; sc.ExecuteNonQuery(); sqc.close(); } ------------------------------------------------------------------- strLocalIP id computers IP Through Query Analyzer 'DROP Database' is working fine but programmatically it's giving exception, 'connection is in use' :) With Regards Manoj

    C J 2 Replies Last reply
    0
    • M manojk_batra

      Dear All, I know this section is regarding C# only,but I am entering regarding SQL Database. I am really sorry for this. I want to Delete the SQL Database programmatically (using C#). I am using following code for Deleting Database. ---------------------------------------------------------- private void DeleteDatabase() { try { String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";"; SqlConnection sqc = new SqlConnection(conn); sqc.Open(); SqlCommand sc = new SqlCommand(); sc.Connection = sqc; sc.CommandText = "DROP DATABASE "+strDatabaseName; sc.ExecuteNonQuery(); sqc.close(); } ------------------------------------------------------------------- strLocalIP id computers IP Through Query Analyzer 'DROP Database' is working fine but programmatically it's giving exception, 'connection is in use' :) With Regards Manoj

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      What exactly is the conn string and the sc.CommandText?


      My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius

      M 1 Reply Last reply
      0
      • M manojk_batra

        Dear All, I know this section is regarding C# only,but I am entering regarding SQL Database. I am really sorry for this. I want to Delete the SQL Database programmatically (using C#). I am using following code for Deleting Database. ---------------------------------------------------------- private void DeleteDatabase() { try { String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";"; SqlConnection sqc = new SqlConnection(conn); sqc.Open(); SqlCommand sc = new SqlCommand(); sc.Connection = sqc; sc.CommandText = "DROP DATABASE "+strDatabaseName; sc.ExecuteNonQuery(); sqc.close(); } ------------------------------------------------------------------- strLocalIP id computers IP Through Query Analyzer 'DROP Database' is working fine but programmatically it's giving exception, 'connection is in use' :) With Regards Manoj

        J Offline
        J Offline
        Johny Ng
        wrote on last edited by
        #3

        Connection is in use or database is in use???Normally, when you want to delete a database, you need to disconnect all current connections.

        M 1 Reply Last reply
        0
        • J Johny Ng

          Connection is in use or database is in use???Normally, when you want to delete a database, you need to disconnect all current connections.

          M Offline
          M Offline
          manojk_batra
          wrote on last edited by
          #4

          Dear Johny Ng, Even after disconnecting all the connections related with Database it's still giving same exception. Some one has suggested me to flush the connection pool, Please let me know How i can flush connection pool in C#. :) Thanks & Regards Manoj

          J 1 Reply Last reply
          0
          • C Colin Angus Mackay

            What exactly is the conn string and the sc.CommandText?


            My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius

            M Offline
            M Offline
            manojk_batra
            wrote on last edited by
            #5

            Dear Colin Angus, The conn String is is the connection String containg computer information in which Database exists , Database name, user and password through which i can login to database. String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";"; strLocalIP is actually is the IP of computer inwhich Database exists. And sc is sqlcommand through which I execute the sql query. Some one has suggested me to flush the connection pool. Please let me know How i can flush connection pool through C#. :) Thanks & Regards Manoj Kumar

            C 1 Reply Last reply
            0
            • M manojk_batra

              Dear Johny Ng, Even after disconnecting all the connections related with Database it's still giving same exception. Some one has suggested me to flush the connection pool, Please let me know How i can flush connection pool in C#. :) Thanks & Regards Manoj

              J Offline
              J Offline
              Johny Ng
              wrote on last edited by
              #6

              Don't know why it's hard for you but you can kill active connection by using kill command. Or if you just want to drop that db, simply stop and start SQL server or set that db to single_user mode so all active connections will be killed.

              1 Reply Last reply
              0
              • M manojk_batra

                Dear Colin Angus, The conn String is is the connection String containg computer information in which Database exists , Database name, user and password through which i can login to database. String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";"; strLocalIP is actually is the IP of computer inwhich Database exists. And sc is sqlcommand through which I execute the sql query. Some one has suggested me to flush the connection pool. Please let me know How i can flush connection pool through C#. :) Thanks & Regards Manoj Kumar

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                No, I wanted the exact values of conn and sc.CommandText. I did not want a description of them. I know what they mean, I want to know what you wrote. My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius

                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