Is it possible to set SQL Server query timeout within Django/South?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a Django app that I have just migrated to South for model/DB synchronization. I have created a new migration after making some changes to the model (ie. adding a new foreign key field). Here is a sample of the code within the new migration
0002_auto__add_field_table_new_field.py



class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'Table.new_field'
db.add_column(u'Table', 'new_field',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['database.other_table'], null=True, blank=True),
keep_default=False)


def backwards(self, orm):
# Deleting field 'Table.new_field'
db.delete_column(u'Table', 'new_field')


When I attempt to apply the migration the query always times out after roughly 30 seconds, with the following error message:




sqlserver_ado,dbapi.DatabaseError: (-2147352567, 'Exception occured.', (0, u'Microsoft SQL Server Native Client 10.0', u'Query timeout expired', None, 0, -2147217871), None)




Is it possible to increase the SQL Server query timeout? I have been unable to find any specific documentation on this other than how to increase the value within SSMS, but having done this it has made no difference. Is this perhaps done in Django settings.py?










share|improve this question





























    1















    I have a Django app that I have just migrated to South for model/DB synchronization. I have created a new migration after making some changes to the model (ie. adding a new foreign key field). Here is a sample of the code within the new migration
    0002_auto__add_field_table_new_field.py



    class Migration(SchemaMigration):

    def forwards(self, orm):
    # Adding field 'Table.new_field'
    db.add_column(u'Table', 'new_field',
    self.gf('django.db.models.fields.related.ForeignKey')(to=orm['database.other_table'], null=True, blank=True),
    keep_default=False)


    def backwards(self, orm):
    # Deleting field 'Table.new_field'
    db.delete_column(u'Table', 'new_field')


    When I attempt to apply the migration the query always times out after roughly 30 seconds, with the following error message:




    sqlserver_ado,dbapi.DatabaseError: (-2147352567, 'Exception occured.', (0, u'Microsoft SQL Server Native Client 10.0', u'Query timeout expired', None, 0, -2147217871), None)




    Is it possible to increase the SQL Server query timeout? I have been unable to find any specific documentation on this other than how to increase the value within SSMS, but having done this it has made no difference. Is this perhaps done in Django settings.py?










    share|improve this question

























      1












      1








      1


      1






      I have a Django app that I have just migrated to South for model/DB synchronization. I have created a new migration after making some changes to the model (ie. adding a new foreign key field). Here is a sample of the code within the new migration
      0002_auto__add_field_table_new_field.py



      class Migration(SchemaMigration):

      def forwards(self, orm):
      # Adding field 'Table.new_field'
      db.add_column(u'Table', 'new_field',
      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['database.other_table'], null=True, blank=True),
      keep_default=False)


      def backwards(self, orm):
      # Deleting field 'Table.new_field'
      db.delete_column(u'Table', 'new_field')


      When I attempt to apply the migration the query always times out after roughly 30 seconds, with the following error message:




      sqlserver_ado,dbapi.DatabaseError: (-2147352567, 'Exception occured.', (0, u'Microsoft SQL Server Native Client 10.0', u'Query timeout expired', None, 0, -2147217871), None)




      Is it possible to increase the SQL Server query timeout? I have been unable to find any specific documentation on this other than how to increase the value within SSMS, but having done this it has made no difference. Is this perhaps done in Django settings.py?










      share|improve this question














      I have a Django app that I have just migrated to South for model/DB synchronization. I have created a new migration after making some changes to the model (ie. adding a new foreign key field). Here is a sample of the code within the new migration
      0002_auto__add_field_table_new_field.py



      class Migration(SchemaMigration):

      def forwards(self, orm):
      # Adding field 'Table.new_field'
      db.add_column(u'Table', 'new_field',
      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['database.other_table'], null=True, blank=True),
      keep_default=False)


      def backwards(self, orm):
      # Deleting field 'Table.new_field'
      db.delete_column(u'Table', 'new_field')


      When I attempt to apply the migration the query always times out after roughly 30 seconds, with the following error message:




      sqlserver_ado,dbapi.DatabaseError: (-2147352567, 'Exception occured.', (0, u'Microsoft SQL Server Native Client 10.0', u'Query timeout expired', None, 0, -2147217871), None)




      Is it possible to increase the SQL Server query timeout? I have been unable to find any specific documentation on this other than how to increase the value within SSMS, but having done this it has made no difference. Is this perhaps done in Django settings.py?







      python sql sql-server django django-south






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 '13 at 16:01









      giogoicegiogoice

      217




      217
























          3 Answers
          3






          active

          oldest

          votes


















          0














          So it turns out that the problem was being caused by the backend python db module sqlserver_ado. It is this module that was determining the query timeout. I have amended my settings.py to now use the sql_server.pyodbc ENGINE instead. The migration has now been applied successfully by making use of this.






          share|improve this answer
























          • Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

            – user193130
            Dec 10 '14 at 23:34



















          0














          If you need to stick with the sqlserver_ado driver, you can set query timeout as described in this question (default is 30 s):
          Query timeout expired in django-mssql when executing custom SQL directly



          DATABASES = {
          'default': {
          'NAME': DATABASE_NAME,
          'ENGINE': 'sqlserver_ado',
          'HOST': DATABASE_HOST,
          'USER': DATABASE_USER,
          'PASSWORD': DATABASE_PASSWORD,
          'COMMAND_TIMEOUT': timeout_in_seconds,
          }
          }





          share|improve this answer

































            0














            This question is a bit old, but it's what comes up at the top of Google's results, so I'd like to add for those coming along later that if you use pyodbc with django-pyodbc (specifically django-pyodbc-azure for more modern Django), there are several settings that may be of interest; note especially the query_timeout setting:





          • connection_timeout

            Integer. Sets the timeout in seconds for the database connection process. Default value is 0 which disables the timeout.





          • connection_retries

            Integer. Sets the times to retry the database connection process. Default value is 5.





          • connection_retry_backoff_time

            Integer. Sets the back off time in seconds for reries of the database connection process. Default value is 5.





          • query_timeout

            Integer. Sets the timeout in seconds for the database query. Default value is 0 which disables the timeout.





          • Adding the query_timeout setting to the database options allowed me to work around an issue that was occurring to a db lock (where the write my code was doing wasn't currently important):



            DATABASES = {
            'default': {
            # ...
            'OPTIONS': {
            'driver': 'FreeTDS',
            'query_timeout': 6,
            },
            },
            }





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19840641%2fis-it-possible-to-set-sql-server-query-timeout-within-django-south%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              So it turns out that the problem was being caused by the backend python db module sqlserver_ado. It is this module that was determining the query timeout. I have amended my settings.py to now use the sql_server.pyodbc ENGINE instead. The migration has now been applied successfully by making use of this.






              share|improve this answer
























              • Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

                – user193130
                Dec 10 '14 at 23:34
















              0














              So it turns out that the problem was being caused by the backend python db module sqlserver_ado. It is this module that was determining the query timeout. I have amended my settings.py to now use the sql_server.pyodbc ENGINE instead. The migration has now been applied successfully by making use of this.






              share|improve this answer
























              • Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

                – user193130
                Dec 10 '14 at 23:34














              0












              0








              0







              So it turns out that the problem was being caused by the backend python db module sqlserver_ado. It is this module that was determining the query timeout. I have amended my settings.py to now use the sql_server.pyodbc ENGINE instead. The migration has now been applied successfully by making use of this.






              share|improve this answer













              So it turns out that the problem was being caused by the backend python db module sqlserver_ado. It is this module that was determining the query timeout. I have amended my settings.py to now use the sql_server.pyodbc ENGINE instead. The migration has now been applied successfully by making use of this.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 8 '13 at 15:57









              giogoicegiogoice

              217




              217













              • Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

                – user193130
                Dec 10 '14 at 23:34



















              • Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

                – user193130
                Dec 10 '14 at 23:34

















              Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

              – user193130
              Dec 10 '14 at 23:34





              Hi, I'm having a similar problem in that I want to change the timeout. Were you using django-mssql? How did you use pyodbc with django?

              – user193130
              Dec 10 '14 at 23:34













              0














              If you need to stick with the sqlserver_ado driver, you can set query timeout as described in this question (default is 30 s):
              Query timeout expired in django-mssql when executing custom SQL directly



              DATABASES = {
              'default': {
              'NAME': DATABASE_NAME,
              'ENGINE': 'sqlserver_ado',
              'HOST': DATABASE_HOST,
              'USER': DATABASE_USER,
              'PASSWORD': DATABASE_PASSWORD,
              'COMMAND_TIMEOUT': timeout_in_seconds,
              }
              }





              share|improve this answer






























                0














                If you need to stick with the sqlserver_ado driver, you can set query timeout as described in this question (default is 30 s):
                Query timeout expired in django-mssql when executing custom SQL directly



                DATABASES = {
                'default': {
                'NAME': DATABASE_NAME,
                'ENGINE': 'sqlserver_ado',
                'HOST': DATABASE_HOST,
                'USER': DATABASE_USER,
                'PASSWORD': DATABASE_PASSWORD,
                'COMMAND_TIMEOUT': timeout_in_seconds,
                }
                }





                share|improve this answer




























                  0












                  0








                  0







                  If you need to stick with the sqlserver_ado driver, you can set query timeout as described in this question (default is 30 s):
                  Query timeout expired in django-mssql when executing custom SQL directly



                  DATABASES = {
                  'default': {
                  'NAME': DATABASE_NAME,
                  'ENGINE': 'sqlserver_ado',
                  'HOST': DATABASE_HOST,
                  'USER': DATABASE_USER,
                  'PASSWORD': DATABASE_PASSWORD,
                  'COMMAND_TIMEOUT': timeout_in_seconds,
                  }
                  }





                  share|improve this answer















                  If you need to stick with the sqlserver_ado driver, you can set query timeout as described in this question (default is 30 s):
                  Query timeout expired in django-mssql when executing custom SQL directly



                  DATABASES = {
                  'default': {
                  'NAME': DATABASE_NAME,
                  'ENGINE': 'sqlserver_ado',
                  'HOST': DATABASE_HOST,
                  'USER': DATABASE_USER,
                  'PASSWORD': DATABASE_PASSWORD,
                  'COMMAND_TIMEOUT': timeout_in_seconds,
                  }
                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 23 '17 at 11:52









                  Community

                  11




                  11










                  answered Jan 17 '16 at 22:05









                  Mr. NapikMr. Napik

                  3,88531818




                  3,88531818























                      0














                      This question is a bit old, but it's what comes up at the top of Google's results, so I'd like to add for those coming along later that if you use pyodbc with django-pyodbc (specifically django-pyodbc-azure for more modern Django), there are several settings that may be of interest; note especially the query_timeout setting:





                    • connection_timeout

                      Integer. Sets the timeout in seconds for the database connection process. Default value is 0 which disables the timeout.





                    • connection_retries

                      Integer. Sets the times to retry the database connection process. Default value is 5.





                    • connection_retry_backoff_time

                      Integer. Sets the back off time in seconds for reries of the database connection process. Default value is 5.





                    • query_timeout

                      Integer. Sets the timeout in seconds for the database query. Default value is 0 which disables the timeout.





                    • Adding the query_timeout setting to the database options allowed me to work around an issue that was occurring to a db lock (where the write my code was doing wasn't currently important):



                      DATABASES = {
                      'default': {
                      # ...
                      'OPTIONS': {
                      'driver': 'FreeTDS',
                      'query_timeout': 6,
                      },
                      },
                      }





                      share|improve this answer




























                        0














                        This question is a bit old, but it's what comes up at the top of Google's results, so I'd like to add for those coming along later that if you use pyodbc with django-pyodbc (specifically django-pyodbc-azure for more modern Django), there are several settings that may be of interest; note especially the query_timeout setting:





                      • connection_timeout

                        Integer. Sets the timeout in seconds for the database connection process. Default value is 0 which disables the timeout.





                      • connection_retries

                        Integer. Sets the times to retry the database connection process. Default value is 5.





                      • connection_retry_backoff_time

                        Integer. Sets the back off time in seconds for reries of the database connection process. Default value is 5.





                      • query_timeout

                        Integer. Sets the timeout in seconds for the database query. Default value is 0 which disables the timeout.





                      • Adding the query_timeout setting to the database options allowed me to work around an issue that was occurring to a db lock (where the write my code was doing wasn't currently important):



                        DATABASES = {
                        'default': {
                        # ...
                        'OPTIONS': {
                        'driver': 'FreeTDS',
                        'query_timeout': 6,
                        },
                        },
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          This question is a bit old, but it's what comes up at the top of Google's results, so I'd like to add for those coming along later that if you use pyodbc with django-pyodbc (specifically django-pyodbc-azure for more modern Django), there are several settings that may be of interest; note especially the query_timeout setting:





                        • connection_timeout

                          Integer. Sets the timeout in seconds for the database connection process. Default value is 0 which disables the timeout.





                        • connection_retries

                          Integer. Sets the times to retry the database connection process. Default value is 5.





                        • connection_retry_backoff_time

                          Integer. Sets the back off time in seconds for reries of the database connection process. Default value is 5.





                        • query_timeout

                          Integer. Sets the timeout in seconds for the database query. Default value is 0 which disables the timeout.





                        • Adding the query_timeout setting to the database options allowed me to work around an issue that was occurring to a db lock (where the write my code was doing wasn't currently important):



                          DATABASES = {
                          'default': {
                          # ...
                          'OPTIONS': {
                          'driver': 'FreeTDS',
                          'query_timeout': 6,
                          },
                          },
                          }





                          share|improve this answer













                          This question is a bit old, but it's what comes up at the top of Google's results, so I'd like to add for those coming along later that if you use pyodbc with django-pyodbc (specifically django-pyodbc-azure for more modern Django), there are several settings that may be of interest; note especially the query_timeout setting:





                        • connection_timeout

                          Integer. Sets the timeout in seconds for the database connection process. Default value is 0 which disables the timeout.





                        • connection_retries

                          Integer. Sets the times to retry the database connection process. Default value is 5.





                        • connection_retry_backoff_time

                          Integer. Sets the back off time in seconds for reries of the database connection process. Default value is 5.





                        • query_timeout

                          Integer. Sets the timeout in seconds for the database query. Default value is 0 which disables the timeout.





                        • Adding the query_timeout setting to the database options allowed me to work around an issue that was occurring to a db lock (where the write my code was doing wasn't currently important):



                          DATABASES = {
                          'default': {
                          # ...
                          'OPTIONS': {
                          'driver': 'FreeTDS',
                          'query_timeout': 6,
                          },
                          },
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 3 at 4:23









                          hlongmorehlongmore

                          7581321




                          7581321






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19840641%2fis-it-possible-to-set-sql-server-query-timeout-within-django-south%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              MongoDB - Not Authorized To Execute Command

                              How to fix TextFormField cause rebuild widget in Flutter

                              in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith