Hello,
I'm developing an add-in with a range of tools and many of them access our SDE database (mostly for reading but sometimes writing). I've been told I should only access it once per session but I'm wondering if there's any examples on the best practice for this.
Currently I've separated it out into a "Data" class, but my implementation feels overcomplicated because I want it to use a different connection string based on the development or production build. Does anyone have any guidance here? Any examples in the documentation?
Here's my current Data class:
public static class Data
{
private static DatabaseConnectionProperties _dbConnectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
{
AuthenticationMode = AuthenticationMode.DBMS,
User = GetCredential("user"),
Password = GetCredential("password"),
Instance = GetCredential("instance")
};
public static DatabaseConnectionProperties dbConnectionProperties
{
get { return _dbConnectionProperties; }
}
private static Geodatabase _sdeGeodatabase = new Geodatabase(_dbConnectionProperties);
public static Geodatabase SDEGeodatabase
{
get => _sdeGeodatabase;
}
private static string GetCredential(string credential)
{
DbConnectionStringBuilder dbConnectionStringBuilder = new DbConnectionStringBuilder();
dbConnectionStringBuilder.ConnectionString = Settings.ConnectionString;
if (credential == "user") return dbConnectionStringBuilder["User ID"].ToString();
if (credential == "password") return dbConnectionStringBuilder["Password"].ToString();
if (credential == "instance") return dbConnectionStringBuilder["Data Source"].ToString();
return null;
}
}
Thanks in advance.
Solved! Go to Solution.
I'm not sure I understand the question. You could read the connection string from a registry key or configuration file or something like that (please don't store a password there 😀).
There's no problem connecting to a single geodatabase multiple times through the Pro SDK. The underlying code will share a single connection.
--Rich
I'm not sure I understand the question. You could read the connection string from a registry key or configuration file or something like that (please don't store a password there 😀).
There's no problem connecting to a single geodatabase multiple times through the Pro SDK. The underlying code will share a single connection.
--Rich