asmgx
asmgx

Reputation: 8004

using pyodbc.cursor cause error in python

I am following this github link to insert into sql server

here is my code

import pyodbc
import pandas as pd

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=******;'
                      'Database=******;'
                      'Trusted_Connection=yes;')

cursor = pyodbc.cursor()

I am getting this error

> Traceback (most recent call last):
> 
>   File "<ipython-input-33-d56faea8bdd3>", line 11, in <module>
>     cursor = pyodbc.cursor()
> 
> AttributeError: module 'pyodbc' has no attribute 'cursor'

Upvotes: 1

Views: 1441

Answers (1)

Sociopath
Sociopath

Reputation: 13401

Use conn.cursor instead of pyodbc.cursor

import pyodbc
import pandas as pd

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=******;'
                      'Database=******;'
                      'Trusted_Connection=yes;')

cursor = conn.cursor()

Refer documentation for more details

Upvotes: 2

Related Questions