如何使用C#将Dll作为连接字符串 [英] How To Make A Dll As A Connection String Using C#

查看:113
本文介绍了如何使用C#将Dll作为连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI Guys





我只是想知道我是否可以将dll作为连接字符串所以我可以在我的winform中使用,只需在我的项目中添加引用并使用dll作为连接字符串。

所以如果服务器有变化,我需要做的只是制作一个新的dll而不是编辑整个程序。

希望你们得到我的观点。

请提供示例或演示项目。因为我刚刚进入c#并制作dll。

谢谢

HI Guys


I was just wondering if i can make a dll as a connection string so that i can use in my winform and just add reference in my project and use the dll as a connection string.
so that if the server has change all i need to do is just make a new dll and not go edit the whole program.
Hope u guys get my point.
Please provide with an example or demo project. since im new into c# and making dll.
thanks

推荐答案

你有app.Config文件可用。所以不要使用dll(只是为了得到一个连接字符串)。使用类似这样的东西



如何从C#中的App.Config获取连接字符串 [ ^ ]



亲切如果它有帮助,请给它评分。
You have app.Config file available. So instead of using dll (just to get a connection string). Use something like this

How to get Connection String from App.Config in C#[^]

Kindly rate it if it helps.


使用静态类创建新的库项目 Utils.cs

Make new library project with static class Utils.cs
namespace MyProject.Utils
{
   public static class Utils
   {
        public const string ConnectionString = @"Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";
   }
}



然后将此程序集绑定到您的项目


then bind this assembly to you project

using MyProject.Utils;

//some code
{
    //some code
    string connString = Utils.ConnectionString;
    //some code
}



希望它能帮到你


hope it's help you


这篇关于如何使用C#将Dll作为连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆