Current filter:
                                You should refresh the page.
                                  • Description:
                                    Is there a way to control the path of the database? I will be creating and working with different databases per client requirements. Basically, I would like to control where I create the database for Firebird, DB2, Pervasive, Access, Postgre, and MS SQL server. Any samples would be greatly appreciated.

                                    Usually, the database connection string contains a path to a database file. You can allow an end-user to change the database path by including it in your application configuration file. For example:

                                    <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ServerType" value="Access" /> <add key="Server" value="" /> <add key="Database" value="E:\data.mdb" /> <add key="User" value="" /> <add key="Password" value="" /> </appSettings> </configuration>

                                    The configuration settings are retrieved via the AppSettingsReader class and then a connection string is composed. We advise that you use the GetConnectionString function of provider classes from the DevExpress.Xpo.DB namespace.

                                    using System.Configuration; using DevExpress.Xpo; private static string GetConnectionString() { AppSettingsReader config = new AppSettingsReader(); string serverType, server, database, user, password; serverType = ((string)(config.GetValue("ServerType", typeof(string)))); server = ((string)(config.GetValue("Server", typeof(string)))); database = ((string)(config.GetValue("Database", typeof(string)))); user = ((string)(config.GetValue("User", typeof(string)))); password = ((string)(config.GetValue("Password", typeof(string)))); switch(serverType) { case "MSSQL": return DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString(server, user, password, database); case "Access": return DevExpress.Xpo.DB.AccessConnectionProvider.GetConnectionString(database, user, password); // ... generate connection strings for other providers, e.g. MySql, Firebird, etc. default: return Session.GetDefaultConnectionString(); } }

                                    The connection string must be assigned to the DefaultSession object at the entry point of your application.

                                    [STAThread] static void Main() { DevExpress.Xpo.Session.DefaultSession.ConnectionString = GetConnectionString(); Application.Run(new Form1()); }

                                    See Also:
                                    How to create a correct connection string for XPO providers?

                                0 Solutions

                                Creation Date Importance Sort by