且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不将配置文件添加到库项目的情况下与数据库建立连接

更新时间:2023-12-06 16:49:40

您可以对连接字符串进行硬编码,不推荐使用.
您可以在应用启动时要求提供连接详细信息.
如果您的项目是DLL,则可以从调用应用程序将其传递.

对我来说,真正的问题是为什么您不想要它在配置文件中?
如果是因为它是纯文本格式,则对连接字符串进行加密,然后在使用时对其进行解密,并仅允许在您的应用程序内部对其进行更改.
Well you can hard code the connection string, not recommended.
You could ask for the connection details when your app starts.
If your project is a DLL you could pass it in from the calling app.

The real question for me is why don''t you want it in the config file?
If it is because it is plain text then encrypt the connection string then decrypt it when you use it and only allow it to be changed from within your app.