Hi everyone!!!
I’m trying to update an external database through code but I’m getting this error:
“Exception has been thrown by the target of an invocation. Invalid authorization specification.”
I have a code to get all the information I need from the external database. I put all the information in a table called parnetInterface.
str exceptionStr;
str connectStr = “Provider=sqloledb;Data Source=”+parnetInterface.IpServer+";Network Library=DBMSSOCN;Initial Catalog="+parnetInterface.DataBase+";User ID="+parnetInterface.User+";Password="+parnetInterface.Pswd;
try
{
perm = new InteropPermission(InteropKind::ClrInterop);
if (perm == null)
throw error(“Need permission”);
perm.assert();
objConn = new System.Data.OleDb.OleDbConnection(connectStr);
objConn.Open();
cmdSelect = objConn.CreateCommand();
cmdSelect.set_CommandText(sqlGlobalStatement);
reader = cmdSelect.ExecuteReader();
while(reader.Read())
{}
catch(Exception::CLRError)
{
CodeAccessPermission::revertAssert();
perm = new InteropPermission(InteropKind::ClrInterop);
if (perm == null)
{
throw error (“Error”);
}
perm.assert();
e = ClrInterop::getLastException();
CodeAccessPermission::revertAssert();
while( e )
{
exceptionStr += e.get_Message();
e = e.get_InnerException();
}
info(exceptionStr);
}
catch
{
error(“Error”);
}
if(objConn)
objConn.Close();
Everything here goes ok, I have no problems here. But when I try to do the same to update my database, I got the error I mentioned. Here is my code:
str connectStr = “Provider=sqloledb;Data Source=”+parnetInterface.IpServer+";Network Library=DBMSSOCN;Initial Catalog="+parnetInterface.DataBase+";User ID="+parnetInterface.User+";Password="+parnetInterface.Pswd;
str exceptionStr;
;
try
{
perm = new InteropPermission(InteropKind::ClrInterop);
if(perm == null)
throw error(“Need permission”);
perm.assert();
objConn = new System.Data.OleDb.OleDbConnection(connectStr);
objConn.Open();
//When I try to go to the next line (the while select) it goes directly to the catch
while select tmpLedgerJournalTrans
{ /* do the update here */ }
objConn.Close();
}
catch(Exception::CLRError)
{
CodeAccessPermission::revertAssert();
perm = new InteropPermission(InteropKind::ClrInterop);
if (perm == null)
{
throw error (“Error”);
}
perm.assert();
e = ClrInterop::getLastException();
CodeAccessPermission::revertAssert();
while( e )
{
exceptionStr += e.get_Message();
e = e.get_InnerException();
}
info(exceptionStr);
}
catch
{
error(“Error”);
}
I don’t know if I’m doing something wrong. I have all the permissions in the database, I can update/create/delete/insert whatever I want in the sql table.
I really appreciate if someone can help me!!! =)