title: Why calling stored procedure in SQL server from x++ break AX?
body: <p>I have a script for renaming column in database written in X++.</p>
  
  <pre><code>public static server void renameColumn()
  {
  str sql;
  Connection          oConnection;
  Statement           oStatement;
  ResultSet           resSet;
  SqlStatementExecutePermission perm;
  
  sql = strFmt( 'use DBNAME; exec sp_rename \'DBNAME.dbo.Table1.Name2\', \'Name1\', \'COLUMN\'');
  oConnection = new Connection();
  oStatement = oConnection.createStatement();
  perm = new SqlStatementExecutePermission(sql);
  perm.assert();
  oStatement.executeUpdate(sql);
  }
  </code></pre>
  
  <p>Which change existing column named <strong>Name2</strong> to <strong>Name1</strong>.</p>
  
  <p>The strange errors start to occures few minutes later after I call it (using job).</p>
  
  <pre><code>Cannot select a record in Current AOS instances (SysServerSessions). ServerId: 0.
  The SQL database has issued an error.
  SQL error description: [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'SYSSERVERSESSIONS'.
  SQL statement: SELECT T1.SERVERID,T1.AOSID,T1.INSTANCE_NAME,T1.VERSION,T1.LOGINDATETIME,T1.LOGINDATETIMETZID,T1.STATUS,T1.LOADBALANCE,T1.WORKLOAD,T1.LASTUPDATEDATETIME,T1.LASTUPDATEDATETIMETZID,T1.AOSACCOUNT,T1.RECVERSION,T1.RECID,T2.SESSIONID,T2.SERVERID,T2.VERSION,T2.LOGINDATETIME,T2.LOGINDATETIMETZID,T2.STATUS,T2.USERID,T2.SID,T2.USERLANGUAGE,T2.HELPLANGUAGE,T2.CLIENTTYPE,T2.SESSIONTYPE,T2.CLIENTCOMPUTER,T2.DATAPARTITION,T2.RECVERSION,T2.RECID FROM SYSSERVERSESSIONS T1 CROSS JOIN SYSCLIENTSESSIONS T2 WHERE ((T2.SERVERID=T1.SERVERID) AND (T2.SESSIONID=?))
  
  Cannot select a record in Alerts - event inbox (EventInbox).
  The SQL database has issued an error.
  SQL error description: [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'EVENTINBOX'.
  SQL statement: SELECT COUNT(T1.RECID) FROM EVENTINBOX T1 WHERE ((PARTITION=?) AND ((((ISREAD=?) AND (USERID=?)) AND (DELETED=?)) AND (VISIBLE=?)))
  </code></pre>
  
  <p>Anyone have an idea how to repair it and what exactly cause it?</p>
  
  <p>Microsoft Dynamics AX 2012 R3
  Microsoft SQL Server 2012</p>
  
  <p>P.S.: It can not be used without <strong>use DBNAME;</strong> because</p>
  
  <pre><code>SQL error description: [Microsoft][SQL Server Native Client 10.0][SQL Server]Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong.
  </code></pre>