Select to view content in your preferred language

Store Database Connection String in App.config for an ArcGIS Pro SDK Add-In 2.x

03-19-2018 11:35 AM
New Contributor III

I have added an app.config file to my visual studio pro SDK project and I’m trying to retrieve a connection string from it. The retrieval code always returns null. I don’t know if that’s because it is a UserControl or running inside ArcGIS Pro or what. Any thoughts? Is there a better place to store the connection string?

Visual Studio 2017, .Net Framework 4.6.1, ArcGIS Pro SDK 2.1, SQL Server


<?xml version="1.0" encoding="utf-8" ?>
        <add name="my_conn" connectionString="Data;Initial Catalog=some_db;User ID=xxx;Password=yyy" />

c# code

// Assume failure.
string returnValue = null;

// Look for the name in the connectionStrings section.
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["my_conn"];

// If found, return the connection string.
if (settings != null)
    returnValue = settings.ConnectionString;

0 Kudos
0 Replies