Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone
I am writing a project which needs to connect to sql server ( with predefined tables) in run time. for example I want to get IP, port, username and password of sqlserver from user and then connect to it and fetch some data. my database table structure is same for all users but IP, port, username and password is different. so how can I connect dynamically in run time?

more information:
there are some Companies which they have a specified predefined database. my program will be installed on the companies client computers. so, I need to get IP, port, username and password of database servers and then create connection string and connect to each database with its own connection string.


thanks
Posted
Updated 11-Jan-14 18:23pm
v2
Comments
Sandeep Singh Shekhawat 11-Jan-14 6:07am    
You can write configuration information in text file and then read connection string from text file dynamicaaly.
Karthik_Mahalingam 11-Jan-14 6:33am    
windows or web ?
xLordProgrammer 11-Jan-14 7:04am    
Windows (desktop application)
Karthik_Mahalingam 11-Jan-14 7:16am    
still i am confused with the requirement..
can u pls add more info..
neymar1107 11-Jan-14 10:31am    
i dont know

There is a constructor for the connection object which takes a connection string, so just pass it through and it won't use the one in your config file.
 
Share this answer
 
You can configure the connection string at the backend. Almost all the DB dll have connectionstring as property.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx[^]

You can refer the following links to create the connection string dynamically

http://stackoverflow.com/questions/16511244/how-to-create-connection-string-dynamically-in-c-sharp[^]

If you think that the database would be same for all the clients then you can import only the required DLL eg: Sql DB needs only System.Data.SqlClient else you can add the needed dll and based on the DB that the client uses you can initiate the connection string

Reference for the DLL's required: http://stackoverflow.com/questions/16511244/how-to-create-connection-string-dynamically-in-c-sharp[^]
 
Share this answer
 

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