Back to Devexpress

XafApplication.ConnectionString Property

expressappframework-devexpress-dot-expressapp-dot-xafapplication-d5cc2a37.md

latest9.6 KB
Original Source

XafApplication.ConnectionString Property

Specifies the connection string used to connect to the application’s database or to the Application Server.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public string ConnectionString { get; set; }
vb
Public Property ConnectionString As String

Property Value

TypeDescription
String

The connection string.

|

Remarks

Your application may have different connection strings for different scenarios (for example, a specific string for each compilation mode). When you create a new XAF application, the Template Kit generates the connection strings for Microsoft SQL Server Express LocalDB. To customize the autogenerated connection strings or create a new string, open the application configuration file and navigate to its connectionStrings section. For more information, refer to the following help topic: Specify EF Core Database Provider in XAF Application.

The XafApplication.ConnectionString property allows you to choose a specific connection string for your application. The following example demonstrates how to specify this property for a WinForms application:

csharp
static class Program {
   static void Main() {
      //...
      MySolutionWindowsFormsApplication application = new MySolutionWindowsFormsApplication();
      application.ConnectionString = 
         ConfigurationManager.ConnectionStrings["ConnectionStringForDevelopment"].ConnectionString;
      //...
      application.Setup();
      //...
   }
}

Note

XAF removes the password from the XafApplication.ConnectionString property value for security reasons (to avoid exposure of sensitive information in logs, errors, and so on). You can access an unmodified connection string in the application configuration file. To do this, use the following API:

The following code snippets (auto-collected from DevExpress Examples) contain references to the ConnectionString property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-how-to-change-connection-to-the-database-at-runtime/CS/XPO/NET_Framework/RuntimeDbChooser.Win/Controllers/CustomLogonController.cs#L9

csharp
string targetDataBaseName = ((IDatabaseNameParameter)Application.Security.LogonParameters).DatabaseName;
string newConnectionString = MSSqlServerChangeDatabaseHelper.PatchConnectionString(targetDataBaseName, Application.ConnectionString);
if(Application.ConnectionString != newConnectionString) {

xaf-how-to-save-the-currently-opened-view-as-a-new-view-variant-at-runtime/CS/E2813.Demo.Win/Program.cs#L29

csharp
if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null) {
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
}

xaf-how-to-enforce-password-complexity-in-xaf/CS/Solution161.Win/Program.cs#L33

csharp
if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null) {
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
}

xaf-separate-employees-data-in-different-departments-using-security-permissions/CS/MainDemo.Win/Program.cs#L26

csharp
if(ConfigurationManager.ConnectionStrings["ConnectionString"] != null) {
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
}

XAF-CRUD-for-Non-Persistent-Objects-Stored-Remotely/CS/NonPersistentObjectsDemo.Web/Global.asax.cs#L36

csharp
if(ConfigurationManager.ConnectionStrings["ConnectionString"] != null) {
    WebApplication.Instance.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
}

xaf-how-to-save-the-currently-opened-view-as-a-new-view-variant-at-runtime/VB/E2813.Demo.Win/Program.vb#L33

vb
If ConfigurationManager.ConnectionStrings("ConnectionString") IsNot Nothing Then
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End If

xaf-how-to-enforce-password-complexity-in-xaf/VB/Solution161.Win/Program.vb#L30

vb
If ConfigurationManager.ConnectionStrings("ConnectionString") IsNot Nothing Then
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End If

xaf-separate-employees-data-in-different-departments-using-security-permissions/VB/MainDemo.Win/Program.vb#L25

vb
If ConfigurationManager.ConnectionStrings("ConnectionString") IsNot Nothing Then
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End If

XAF-CRUD-for-Non-Persistent-Objects-Stored-Remotely/VB/NonPersistentObjectsDemo.Win/Program.vb#L37

vb
If ConfigurationManager.ConnectionStrings("ConnectionString") IsNot Nothing Then
    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End If

XAF-implement-custom-permission-role-and-user-objects/VB/SecuredExportExample.Web/Global.asax.vb#L34

vb
InMemoryDataStoreProvider.Register()
WebApplication.Instance.ConnectionString = InMemoryDataStoreProvider.ConnectionString
AddHandler CType(WebApplication.Instance.Security, SecurityStrategy).CustomizeRequestProcessors, Sub(s As Object, args As CustomizeRequestProcessorsEventArgs)

See Also

Apply Different Configurations for Development and Production

Deployment

XAF0013: Avoid reading the XafApplication.ConnectionString property

XafApplication Class

XafApplication Members

DevExpress.ExpressApp Namespace