ArcGIS Pro Add-In SDK C# Issue: Create SQL Server database connection connects to different database

578
2
01-14-2022 06:09 AM
JadedEarth
Occasional Contributor

I'm using ArcGIS Pro version 2.9 and Visual Studio 2019 C# language.

I have an Add-In app that creates a SQL Server database connection. Problem is it connects to
a different database even though I specified the actual database name.

Code snippet:

 

 

private void ConnectToSQLServerDb()
{
    try
    {
        string outFolder = E:\WorkingFolder\MyAddIn;
	string outName = "MGConnection.sde";

	var args = Geoprocessing.MakeValueArray(outFolder, outName, "SQL SERVER", "ServerInstance", "OPERATING_SYSTEM_AUTH", "MGDatabase");
	var gp_result = Geoprocessing.ExecuteToolAsync("CreateDatabaseConnection_management", Geoprocessing.MakeValueArray(args.ToArray()));


	ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Finished creating database connection: ", "Result", MessageBoxButton.OK, MessageBoxImage.Information);
    }
    catch (Exception ex)
    {
	ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create database connection: " + ex.Message, "Error Message", MessageBoxButton.OK, MessageBoxImage.Error);
    }
} 

 

 

 

Appreciate any help.

0 Kudos
2 Replies
JadedEarth
Occasional Contributor

Never mind.  I tried using the Geoprocessing tool and it's doing the same thing as my code.

0 Kudos
ParhatM
New Contributor II

 

Were you able to connect to your SQL Server this way? Mine is not working. It says connected successfully but it's not (no connections made on the server side). 

0 Kudos