Forum Discussion

nadim96's avatar
nadim96
New Member
3 years ago

ADO connection to delete record

hello 
I have MS SQL Server and using python for TC scripting.
my query to select and retreve data from the DB works fine. the problem is with the below script for deleting a record.
I have the required DB permissions and the query works fine from MS SQL. the DB connection work fine as well.

def TestSQL_ADO():
Qry = ADO.CreateADOQuery();
Qry.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=ConnectDB; Server = 9.9.9.9; Database=myDB;user id =nadim;password=****"
Qry.SQL = "Delete From Login.User Where User_Login_Name = 'NADIM1'"
Qry.ExecSQL()
Qry.Close()

 



  • Kitt's avatar
    Kitt
    Regular Contributor

    Is the name of your database "Login.User"? You may want to wrap your db objects in [], like this:

    Qry.SQL = "Delete From [Login.User] Where [User_Login_Name] = 'NADIM1'"

     

    If "Login" is the name of your database then you can either remove it and just reference the "User" table OR add the ".dbo." identifier between the db and table names, like this:

    Qry.SQL = "Delete From Login.dbo.User Where User_Login_Name = 'NADIM1'"