<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with connection to MSSQL database in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993301#M953972</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Jun 2008 09:37:16 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-16T09:37:16Z</dc:date>
    <item>
      <title>Problem with connection to MSSQL database</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993300#M953971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry if there is an answer already but i've searched for the solution half a day and hasn't found any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to export the data from SAP HR system to MSSQL database using ADODB. So I have a form for opening the connection and for running sql statements like select and insert. Everything works great when I run this program in SAP GUI via SA38. It makes all the changes it should do like:&lt;/P&gt;&lt;P&gt;- running select statement and returning the results&lt;/P&gt;&lt;P&gt;- delete records from destination table&lt;/P&gt;&lt;P&gt;- insert records into destination table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is when I try to run it in background which in fact is what I need since this application should provide the data to MSSQL on regular dayly basis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It just does not make any changes on the destination database. Strange thing is that all of the statements like &lt;/P&gt;&lt;P&gt;CREATE OBJECT or CALL METHOD return with subrc = 0. But for instance the select statement which should return the results does not change the initial value of statement. So if you look at the code below, the statement &lt;/P&gt;&lt;P&gt;"select count(*) from addSAPHRIMPORT" normally returns the number and the pipe but when it runs in background the value doesn't change so after running this command I still have this select value in sql variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore I cannot find where the problem is. The program runs without errors but has no effect on destination database. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code I use (many writes were added only for testing reasons so do not be scared &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*opening connection to MSSQL&lt;/P&gt;&lt;P&gt;FORM openconnection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  sql = 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=xxxxxx;Password=yyyyyy;Initial Catalog=schema_name;Data Source=db_server_dns_name'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF con-header IS INITIAL OR con-handle = -1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CREATE OBJECT con 'ADODB.Connection'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    write : / 'The result: ', sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF NOT sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CREATE OBJECT rec 'ADODB.Recordset'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    write : / 'The result : ', sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF NOT sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL METHOD OF con 'Open'&lt;/P&gt;&lt;P&gt;    EXPORTING&lt;/P&gt;&lt;P&gt;      #1 = sql.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;        write: / 'Connection error', sy-subrc.&lt;/P&gt;&lt;P&gt;      else.&lt;/P&gt;&lt;P&gt;        write : / sql.&lt;/P&gt;&lt;P&gt;      endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM.                    "openconnection&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;operations on database&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM get_rec.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  sql = 'select count(*) from addSAPHRIMPORT;'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL METHOD OF rec 'OPEN'&lt;/P&gt;&lt;P&gt;    EXPORTING&lt;/P&gt;&lt;P&gt;    #1 = sql&lt;/P&gt;&lt;P&gt;    #2 = con&lt;/P&gt;&lt;P&gt;    #3 = '1'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      WRITE: / 'OK'.&lt;/P&gt;&lt;P&gt;    ELSE.&lt;/P&gt;&lt;P&gt;      WRITE: / 'Error: ', sy-subrc.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CALL METHOD OF rec 'getstring' = sql&lt;/P&gt;&lt;P&gt;      EXPORTING&lt;/P&gt;&lt;P&gt;      #1 = '2'&lt;/P&gt;&lt;P&gt;      #2 = 1&lt;/P&gt;&lt;P&gt;      #3 = '|'&lt;/P&gt;&lt;P&gt;      #4 = '|'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      REFRESH spl. CLEAR spl.&lt;/P&gt;&lt;P&gt;      WRITE: / sql.&lt;/P&gt;&lt;P&gt;      SPLIT sql AT '|' INTO noOfRecs xxx.&lt;/P&gt;&lt;P&gt;      WRITE: / 'Number of records: ', noOfRecs.&lt;/P&gt;&lt;P&gt;    ELSE.&lt;/P&gt;&lt;P&gt;      WRITE: / 'Błąd: ', sy-subrc.&lt;/P&gt;&lt;P&gt;      noOfRecs = 0.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL METHOD of rec 'Close'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    sql = 'delete from [addSAPHRIMPORT]; '.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CALL METHOD OF rec 'Open'&lt;/P&gt;&lt;P&gt;      EXPORTING&lt;/P&gt;&lt;P&gt;      #1 = sql&lt;/P&gt;&lt;P&gt;      #2 = con&lt;/P&gt;&lt;P&gt;      #3 = '1'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      WRITE : / 'Records deleted'.&lt;/P&gt;&lt;P&gt;    ELSE.&lt;/P&gt;&lt;P&gt;      WRITE : / 'ERROR'.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; ENDIF.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CALL METHOD of rec 'Close'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  counter = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;refresh spl.&lt;/P&gt;&lt;P&gt;clear spl.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;LOOP with created inserts earlier in the program&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT dbComm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   write : / dbComm-sqlStr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   CALL METHOD OF rec 'OPEN'&lt;/P&gt;&lt;P&gt;      EXPORTING&lt;/P&gt;&lt;P&gt;      #1 = dbComm-sqlStr&lt;/P&gt;&lt;P&gt;      #2 = con&lt;/P&gt;&lt;P&gt;      #3 = '1'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;      add 1 to counter.&lt;/P&gt;&lt;P&gt;    ELSE.&lt;/P&gt;&lt;P&gt;      write : 'ERROR: '.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL METHOD of rec 'Close'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write : / 'Inserted ', counter, ' records'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERFORM close_connection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDFORM.                    "Get_Rec&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;closing connection&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM close_connection.&lt;/P&gt;&lt;P&gt;  FREE rec.&lt;/P&gt;&lt;P&gt;  FREE con.&lt;/P&gt;&lt;P&gt;ENDFORM.                    "closeconnection&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Pawel Knapik on Jun 10, 2008 2:00 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2008 11:59:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993300#M953971</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-10T11:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with connection to MSSQL database</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993301#M953972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2008 09:37:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993301#M953972</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-16T09:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with connection to MSSQL database</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993302#M953973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I also want to connect from ABAP to MSSQL. CAn you send the code  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Santhikumar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Sep 2008 05:56:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-connection-to-mssql-database/m-p/3993302#M953973</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-03T05:56:31Z</dc:date>
    </item>
  </channel>
</rss>

