title: HY090 - Invalid string or buffer length (0)
body: <p>I am trying to insert data to a table by using .sql file with many insert statements.</p>
  
  <p>Statement looks like below:</p>
  
  <pre><code>INSERT [dbo].[table_name] ([col1], [col2], [col3], [col4], [col5], [col6], [col7], [col8], [col9], [col10], [col11], [col12], [col13], [col14], [col15], [col16], [col17], [col18], [col19], [col20], [col21], [col22], [col23], [col24], [col25]) VALUES (N'01111', N'SOME RANDOM NAME', N'ABCDE', N'Times', N'ABCD', N'0#aa:', N'06', N'SM', N'123 Cerfdty', N'NULL', N'SM', N'NULL', N'NULL', N'000', N'o2:aq', N'wef0', N'000', N'xx:xx', N'xxxxx', N'ZM', NULL, NULL, NULL, NULL, NULL)
  GO
  </code></pre>
  
  <p>Each statement is executed individually and committed after that by reading the file.</p>
  
  <p>But after completing around 240 insert statements, I get the following error:</p>
  
  <blockquote>
    <p>pyodbc.Error: ('HY090', '[HY090] [Microsoft][ODBC Driver Manager] Invalid string or buffer length (0) (SQLExecDirectW)')</p>
  </blockquote>
  
  <ul>
  <li>Python: 3</li>
  <li>pyodbc: 4.0.17</li>
  <li>OS: Windows 10</li>
  <li>DB: Microsoft SQL Server</li>
  <li>driver:
  ['SQL Server',
  'SQL Server Native Client 11.0',
  'ODBC Driver 13 for SQL Server',
  'ODBC Driver 17 for SQL Server']</li>
  </ul>
  
  <p>I tried with above drives to connect. But i get the same error with all driver options. I am running in my local machine to connect Microsoft SQL server.</p>
  
  <p>When I started reading about this issue, I found documents under Microsoft which states:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlbindparameter-function?view=sql-server-2017" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlbindparameter-function?view=sql-server-2017</a></p>
  
  <p>HY090 | Invalid string or buffer length | (DM) The value in BufferLength was less than 0. (See the description of the SQL_DESC_DATA_PTR field in SQLSetDescField.)</p>
  
  <p><a href="https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetdescfield-function?view=sql-server-2017" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetdescfield-function?view=sql-server-2017</a></p>
  
  <p>Some Binding parameter needs to be set to clear the buffer but I am not seeing any information available or options available to use in pyodbc i think. </p>
  
  <p>I maybe clearly diverted from the original cause of this issue.</p>
  
  <p>Kindly assist me with this issue.</p>
  
  <pre><code>try:
      with open(filename,'r') as sqlfile:
          sql_query = ''
          count =0
          for line in sqlfile:
              if 'GO' in line:
                  cursor.execute(sql_query)
                  sql_query = ''
                  conn.commit()
                  count = count +1
                  print(count)
              elif 'PRINT' in line:
                  display = line.split("'")[1]
                  print(display)
              else:
                  sql_query = sql_query + line 
          sqlfile.close()
  except pyodbc.ProgrammingError as error:
      print(error)
  </code></pre>