HOW TO
In the previous article on Creating Attribute Rules to Access Feature Classes in a Different Database, we explored creating and registering a view that accesses a feature class in a different enterprise geodatabase on the same SQL Server instance. The view was subsequently used in authoring an Attribute Rule. This article takes a slightly different approach by creating the view on a separate SQL server instance. This is useful especially when you do not have the required permissions to query the feature class you want to use in authoring your Attribute Rule.
In this example, using Microsoft SQL Server, we are trying to access the FAVORITEFOODANDLOCALE feature class owned by DataLabOwner stored in the DataLab geodatabase on a different instance, on the same network. To achieve this, we must create a database link to access the data on the separate instance.
Use sqlDatabase
Go
Create view DataAdmin.vw_FavoriteFoodandLocale_LS1
as
Select *
from
OPENQUERY([10.150.51.50],
'Select
OBJECTID,
Place,
Item,
IsBeverage,
State,
Shape,
GlobalID,
GDB_GEOMATTR_DATA
From DataLab.DataLabOwner.FAVORITEFOODANDLOCALE')
In this example, sqlDatabase is the active database on my instance and the name of the view is vw_FavoriteFoodandLocale_LS1 with the schema owner as DataAdmin. The OPENQUERY method is being passed to allow us to execute a pass-through query to access tables in the linked server [10.150.51.50].
The view is registered with the geodatabase and is accessible using Arcade with the $datastore function when setting up an Attribute Rule, as shown in the example and image below.
var fnl = FeatureSetByName
($datastore,"DATAADMIN.vw_FavoriteFoodandLocale_LS1, ["Place"])
var ffnl = Intersects(fnl, $feature)
var F = First(ffnl)
//var NPharma = NearestCoordinate(Fpharma, $feature)
if (F == null) return {"errorMessage: "Outside the county"}
return F.Place
This Attribute Rule populates a field (FnL) in a polygon feature class (DATAADMIN.Counties) with the place name of an intersecting (DATAADMIN.vw_FavoriteFoodandLocale_LS1) view layer, as shown in the next image.
In this article, we explored creating a view in SQL Server database that references a feature class from another database in a different SQL Server instance. We created a linked server to the target instance while connecting as a data owner, which gave us the permission to access and query the layer in our active instance.
After registering the view with the database, we were able to refer to the view via an Arcade expression when setting up an attribute rule to generate information based on the attributes in the feature class in the other instance.
Get help from ArcGIS experts
Download the Esri Support App