문제

If we want in our WPF application to let a user make a SQL Server db connection settings through dialog window, what approach we should use in implementing this.

Should we programmatically make changes to the app.config file? Or, some another approach exists? Or, maybe, in WPF there is some prebuilt tools for doing this?

도움이 되었습니까?

해결책

You could always use one of the built-in dialogs. There is an ADODB connection dialog that requires COM interop. There's also one that has a dependency on a Visual Studio DLL.

But Microsoft has also released the source code to the standard connection dialog available on Code Gallery.

As far as storing the connection string, I would avoid assuming you can write to the App.config unless your application is being installed on a per-user basis. Instead I would store it as a user-scoped setting. If you will allow the user to store the password in the connection string, you should first encrypt the string using the ProtectedData class. Note that you should probably use the per-user scope when encrypting.

다른 팁

Regardless of how you build the connection string, it needs to get into your config file which is supported by ConfigurationManager as long as the user has rights to save the config file in the location where it's being installed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top