Python Forum
The INSERT permission was denied on the object
Thread Rating:
  • 1 Vote(s) - 1 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
#4
Do you believe you are currently connected to two databases simultaneously? Could you display that code? planet clicker
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Circumvent the "access denied" page? Pedroski55 7 393 Jun-15-2024, 06:25 AM
Last Post: Pedroski55
  Delete file with read-only permission, but write permission to parent folder cubei 6 22,469 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  KivyMD android app - problem with permission polak7gt 0 395 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 904 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 1,244 Aug-09-2023, 01:24 PM
Last Post: erg
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,954 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,229 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 10,671 Feb-05-2022, 06:14 PM
Last Post: snippsat
  AttributeError: 'Node' object has no attribute 'insert' Anldra12 4 6,704 May-11-2021, 10:12 AM
Last Post: Anldra12
  Error no 13: Permission denied in python shantanu97 1 6,433 Mar-31-2021, 02:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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