I want to generalise the getting connection for that I write a method in C# Class file like this
public SqlConnection GetConnection(SqlConnection objSqlCon)
{
SqlConnection con = new SqlConnection();
try
{
objSqlCon.ConnectionString = con.ConnectionString();
objSqlCon.Open();
return objSqlCon;
}
catch(Exception e)
{
}
}
it shows an error like this
'System.Data.SqlClient.SqlConnection.ConnectionString' is a 'property' but is used like a 'method'
or else can u please tell me the another way to get connection by passing sqlconnection to that method.
Thanks in Advance.
Loading

Abhay ShankerRank #375 · 6.7K reputationPosted Dec 5, 2013, 6:52 AM EST
srujana thallam67 reputationPosted Dec 5, 2013, 6:57 AM EST
But I want to create a method like when ever i want to open a connection i just call this method by passing connection like this am expecting.
Jignesh TrivediRank #16 · 50.3K reputationPosted Dec 5, 2013, 6:18 PM EST
hi,
ConnectionString is property of connection object not method,
so remove braket from end..
try...
public SqlConnection GetConnection(SqlConnection objSqlCon)
{
SqlConnection con = new SqlConnection();
try
{
objSqlCon.ConnectionString = con.ConnectionString;
objSqlCon.Open();
return objSqlCon;
}
catch (Exception e)
{
return null;
}
}
hope this will help you.