<?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 fetching data through odbc connection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/fetching-data-through-odbc-connection/m-p/460905#M36103</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to connect to an external SQL server with a table with an x and y fields using pyodbc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Next I am making an XYEventLayer using arcpy, and then converting the XYEventLayer to a feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run the code outside of ArcView it chokes and says the dataset is not supported or does not exist.&amp;nbsp; I am not sure if calling the APP keyword is the correct way to do this. When I use the ???arcpy.ListDatasets()??? command I just get ???()??? return.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you in advance for your help&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=Pass;SERVER=****.usace.army.mil; DATABASE=ftord; APP=MyApp')
arcpy.env.workspace= 'MyApp'
in_Table = "dbo.Wells_view"
y_coords = "northing"
x_coords = "easting"
out_layer = "wells"
arcpy.env.overwriteOutput = 'true'
saved_Layer = r"G:\Temp\Bart\layers\Wells.lyr"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer)
arcpy.FeatureClassToFeatureClass_conversion("Wells", r"G:\Temp\Bart\scratch.gdb", "wells")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Aug 2011 23:08:27 GMT</pubDate>
    <dc:creator>BartKowalski</dc:creator>
    <dc:date>2011-08-15T23:08:27Z</dc:date>
    <item>
      <title>fetching data through odbc connection</title>
      <link>https://community.esri.com/t5/python-questions/fetching-data-through-odbc-connection/m-p/460905#M36103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to connect to an external SQL server with a table with an x and y fields using pyodbc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Next I am making an XYEventLayer using arcpy, and then converting the XYEventLayer to a feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run the code outside of ArcView it chokes and says the dataset is not supported or does not exist.&amp;nbsp; I am not sure if calling the APP keyword is the correct way to do this. When I use the ???arcpy.ListDatasets()??? command I just get ???()??? return.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you in advance for your help&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=Pass;SERVER=****.usace.army.mil; DATABASE=ftord; APP=MyApp')
arcpy.env.workspace= 'MyApp'
in_Table = "dbo.Wells_view"
y_coords = "northing"
x_coords = "easting"
out_layer = "wells"
arcpy.env.overwriteOutput = 'true'
saved_Layer = r"G:\Temp\Bart\layers\Wells.lyr"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer)
arcpy.FeatureClassToFeatureClass_conversion("Wells", r"G:\Temp\Bart\scratch.gdb", "wells")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 23:08:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fetching-data-through-odbc-connection/m-p/460905#M36103</guid>
      <dc:creator>BartKowalski</dc:creator>
      <dc:date>2011-08-15T23:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: fetching data through odbc connection</title>
      <link>https://community.esri.com/t5/python-questions/fetching-data-through-odbc-connection/m-p/460906#M36104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;I am trying to connect to an external SQL server with a table with an x and y fields using pyodbc.&lt;BR /&gt;Next I am making an XYEventLayer using arcpy, and then converting the XYEventLayer to a feature class.&lt;BR /&gt;When I run the code outside of ArcView it chokes and says the dataset is not supported or does not exist.&amp;nbsp; I am not sure if calling the APP keyword is the correct way to do this. When I use the �??arcpy.ListDatasets()�?? command I just get �??()�?? return.&lt;BR /&gt;Thank you in advance for your help&lt;BR /&gt; &lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import pyodbc
from arcpy import env
cnxn = pyodbc.connect('Driver={SQL Server Native Client 10.0};UID=user;PWD=Pass;SERVER=****.usace.army.mil; DATABASE=ftord; APP=MyApp')
arcpy.env.workspace= 'MyApp'
in_Table = "dbo.Wells_view"
y_coords = "northing"
x_coords = "easting"
out_layer = "wells"
arcpy.env.overwriteOutput = 'true'
saved_Layer = r"G:\Temp\Bart\layers\Wells.lyr"
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_layer)
arcpy.FeatureClassToFeatureClass_conversion("Wells", r"G:\Temp\Bart\scratch.gdb", "wells")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeXYEventLayer_management wouldn't work in this case. Because in_Table is not a arcpy Table View rather than a table or view from pyodbc. One solution you can try is to create a feature class using arcpy.CreateFeatureclass_management. Then loop through the pyodbc cursor on your in_Table and use arcpy.InsertCursor to add each row from pyodbc cursor to the feature class.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:30:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fetching-data-through-odbc-connection/m-p/460906#M36104</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2021-12-11T20:30:43Z</dc:date>
    </item>
  </channel>
</rss>

