private string GetDatabaseUser(IEditor editor) { IDatabaseConnectionInfo databaseConnectionInfo = editor.EditWorkspace as IDatabaseConnectionInfo; if (databaseConnectionInfo != null) { return(databaseConnectionInfo.ConnectedUser); } else { return(String.Empty); } }
private static IDatabase GetDatabase(IDatabaseConnectionInfo databaseConnectionInfo, IsolationLevel isolationLevel) { Guard.ThrowIfNull(databaseConnectionInfo, nameof(databaseConnectionInfo)); Guard.ThrowIfNullOrWhitespace(databaseConnectionInfo.ConnectionString, nameof(databaseConnectionInfo.ConnectionString)); var givenProviderName = databaseConnectionInfo.ProviderName; var providerName = string.IsNullOrWhiteSpace(givenProviderName) ? null : givenProviderName; return(new Database(databaseConnectionInfo.ConnectionString, providerName) { IsolationLevel = isolationLevel }); }
//Current user is obtained edit workspace (if RDBMS) or from Windows private String getCurrentUser() { // Get the base class' workspace. IWorkspace workspace = ArcMap.Editor.EditWorkspace; int userFieldLength = 100; // If supported, use the IDatabaseConnectionInfo interface to get the username. IDatabaseConnectionInfo databaseConnectionInfo = workspace as IDatabaseConnectionInfo; if (databaseConnectionInfo != null) { String connectedUser = databaseConnectionInfo.ConnectedUser; if (connectedUser.ToUpper() != "DBO") { // If the user name is longer than the user field allows, shorten it. if (connectedUser.Length > userFieldLength) { connectedUser = connectedUser.Substring(0, userFieldLength); } return(connectedUser); } } // Get the current Windows user. String userDomain = Environment.UserDomainName; String userName = Environment.UserName; String qualifiedUserName = String.Format(@"{0}\{1}", userDomain, userName); // If the user name is longer than the user field allows, shorten it. if (qualifiedUserName.Length > userFieldLength) { qualifiedUserName = qualifiedUserName.Substring(0, userFieldLength); } return(qualifiedUserName); }
/// <summary> /// Gets the name of the extension's user. For local geodatabases, this is the username as known /// by the operating system (in a domain\username format). For remote geodatabases, the /// IDatabaseConnectionInfo interface is utilized. /// </summary> /// <returns>The name of the current user.</returns> private String GetCurrentUser() { // Get the base class' workspace. IClass baseClass = classHelper.Class; IDataset dataset = (IDataset)baseClass; IWorkspace workspace = dataset.Workspace; // If supported, use the IDatabaseConnectionInfo interface to get the username. IDatabaseConnectionInfo databaseConnectionInfo = workspace as IDatabaseConnectionInfo; if (databaseConnectionInfo != null) { String connectedUser = databaseConnectionInfo.ConnectedUser; // If the user name is longer than the user field allows, shorten it. if (connectedUser.Length > userFieldLength) { connectedUser = connectedUser.Substring(0, userFieldLength); } return(connectedUser); } // Get the current Windows user. String userDomain = Environment.UserDomainName; String userName = Environment.UserName; String qualifiedUserName = String.Format(@"{0}\{1}", userDomain, userName); // If the user name is longer than the user field allows, shorten it. if (qualifiedUserName.Length > userFieldLength) { qualifiedUserName = qualifiedUserName.Substring(0, userFieldLength); } return(qualifiedUserName); }
public IDatabase CreateForReadOnly(IDatabaseConnectionInfo databaseConnectionInfo) => GetDatabase(databaseConnectionInfo, IsolationLevel.ReadUncommitted);
public IDatabase CreateForReadWrite(IDatabaseConnectionInfo databaseConnectionInfo) => GetDatabase(databaseConnectionInfo, IsolationLevel.ReadCommitted);
public SqlDataAccessHelper(ILoggingService loggingService, IConfiguration configuration, IDatabaseConnectionInfo dbInfo) : this(loggingService, configuration, DatabaseHelper.BuildConnectionString(dbInfo.Server, dbInfo.Username, dbInfo.Password, dbInfo.DBName, false, dbInfo.FullApplicationName)) { }