Inorder to return connection from class file you need to change the return type.
void doesn't return any value. So modify the return type.
Abstract class
using System.Data.SqlClient;
public abstract class AbstractClass1
{
public abstract SqlConnection DBConnection();
}
Connection class
using System.Data.SqlClient;
public class Connection : AbstractClass1
{
public override SqlConnection DBConnection()
{
// The body of DBConnection is provided here
SqlConnection con = new SqlConnection("Data Source = xxxxxx; Initial Catalog = Test; User ID = sa,;Password=xxxxx");
return con;
}
}
Then call the class to read the connection.
Connection con = new Connection();
string constr = con.DBConnection().ConnectionString;