Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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
Posted
Updated 28-Aug-14 19:25pm
v2
Comments
Jameel VM 29-Aug-14 1:38am    
wherever you want to pass the connection string in your application,you should specify it.right?
Peter_Daly 29-Aug-14 2:28am    
Yes but for example
i have a pc1 and i made the connection string to pc1 from pc2 pc3 and so on
and at a point pc1 had crash and i need to still run the software.
since all the software in pc2,pc3 are all having a connection string to pc1 and now that pc1 has crash so i would definitely get error and my software wont run.
But if i have a dll as a connection string even if pc1 has crash all i need to do is edit the connection string in the dll.
Hope u get my point.

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.
 
Share this answer
 
Comments
Peter_Daly 29-Aug-14 2:22am    
But after i release my project i wont be able to see app.config
So if i make a dll connection string and my server is change i wont have to go again to the project and edit on the connection string
but what ill need to do is just remake a new dll(which contain a connection string) and enter the new server name and so on.
Hope u get my point
Jameel VM 29-Aug-14 2:31am    
Then how you update the connection string when server change? you should update the dll.right?
Peter_Daly 29-Aug-14 2:32am    
yes u got my point :) Finally
So is there any way we can do that
Mayank Vashishtha 29-Aug-14 3:30am    
Peter, Can you replace the new dll's on server?
Peter_Daly 30-Aug-14 6:40am    
Duh.... ill just compile a new dll and replace it lol and wala its easy :D
Make new library project with static class Utils.cs
C#
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
C#
using MyProject.Utils;

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

hope it's help you
 
Share this answer
 
v5
Comments
Peter_Daly 30-Aug-14 6:41am    
Thanks @john1977 Ur da Man But let me try hope it works :D as i wanted coz by looking to the codes looks like its just wat i need
but a practical test is need :D and i'll let u guys know on the out come of it :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900