Python Forum
The INSERT permission was denied on the object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The INSERT permission was denied on the object
#1
Hi,
I'm trying to use Python to insert data into a SQL Server. pyodbc
I'm basically using python to export data from Server1 & Import into Server 2. with the same database / table names.
I hold the data in a dataframe called DATA
The export works & I can see the rows in my DATA dataframe.
When I try to import the data using the following code to Server 2 I receive an error

Error:
ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The INSERT permission was denied on the object 'dimEmployee', database 'MIS_DM_Common', schema 'conform'. (229) (SQLExecDirectW)")
My test python INSERT code
for index, row in DATA.iterrows():
     cursor.execute("INSERT INTO MIS_DM_Common.conform.DimEmployee (EmployeeConfKey,SalaryNumberWWWGDWEmployeeKey,WWWEmployeeID,WWWEmployeeNumber,Surname,FirstName,Middlename,PreferredName,EmployeeTitle,CurrentActiveIndicator,InsertEventLogKey,UpdateEventLogKey) values('1','B','C','D','E','F','G','H','I','J','1','1','1')")
connectionB.commit()
cursor.close()
I've checked that I have permission on SQL server.
in Microsoft SQL Server Manager Studio I can execute & it works fine
INSERT INTO MIS_DM_Common.conform.DimEmployee (EmployeeConfKey,SalaryNumber,WWWGDWEmployeeKey,WWWEmployeeID,WWWEmployeeNumber,Surname,FirstName,Middlename,PreferredName,EmployeeTitle,CurrentActiveIndicator,InsertEventLogKey,UpdateEventLogKey)
values('1','B','C','D','E','F','G','H','I','J','1','1','1');
(1 row affected)

Checking with shows that the data has been inserted, so I know I have write permissions.
SELECT * FROM MIS_DM_Common.conform.DimEmployee
I've also ensured that I've ran the following on SQL server, as EmployeeConfKey is a PK that I want to specify.
SET IDENTITY_INSERT MIS_DM_Common.conform.DimEmployee ON
My python connection works as I execute a COUNT query on Server2 before executing the INSERT & everything works.

I've also used this code on a 2nd project (Moving data from Server1 to Server2 (but a different table)) & it has worked successfully. My other project did not have a PK as a sequential number, so I'm assuming it has something to do with the PK.

Thanks in advance.
Steven
Reply
#2
Do you think you have two database connections st the same time? Can you show that code?
Reply
#3
(Feb-25-2023, 08:11 PM)deanhystad Wrote: Do you think you have two database connections st the same time? Can you show that code?

You were correct.
I did not close Server1 correctly & used the same code for Server2.

Thanks for the info..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  KivyMD android app - problem with permission polak7gt 0 298 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 726 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 1,050 Aug-09-2023, 01:24 PM
Last Post: erg
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,820 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,134 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 9,860 Feb-05-2022, 06:14 PM
Last Post: snippsat
  AttributeError: 'Node' object has no attribute 'insert' Anldra12 4 6,472 May-11-2021, 10:12 AM
Last Post: Anldra12
  Error no 13: Permission denied in python shantanu97 1 6,191 Mar-31-2021, 02:15 PM
Last Post: snippsat
  Access denied not able to do anything 8( What do i do? MurphysLaw 3 3,781 Oct-20-2020, 08:16 AM
Last Post: snippsat
  How a Mac OS software can restart itself with admin permission in Python 3.7? Formationgrowthhacking 0 1,789 Sep-03-2020, 05:29 PM
Last Post: Formationgrowthhacking

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020