Click here to Skip to main content
15,997,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a function to get dynamic sql connection string,
but its not returning value when I am calling this function

What I have tried:

Function Decleration

public string GetConnectionString()
   {
       //return "Data Source=DELL\\HRMS; " +
       //    " Integrated Security=true;" +
       //    "Initial Catalog=CL1COM0032;";

       Common cmn = new Common();
       SqlConnection connn = new SqlConnection();
       connn = cmn.getConnectionForCompany(uInfo.prDBName);
       connn.Open();
       return connn.ToString();
   }



Function Calling
string connectionString = GetConnectionString();
Posted
Updated 1-Aug-17 23:12pm

1 solution

The ToString method doesn't return the connection string; you're looking for the ConnectionString[^] property:
C#
public string GetConnectionString()
{
    return cmn.getConnectionForCompany(uInfo.prDBName).ConnectionString;
}
 
Share this answer
 
v2
Comments
arvindcis 2-Aug-17 5:35am    
thankyou very much
Thomas Daniels 2-Aug-17 5:37am    
You're welcome!

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