Hi @BenTam-3003 , Welcome to Microsoft Q&A,
Your usage is wrong.
Instantiation of the SqlConnectn class should use new SqlConnectn().
The method name of the SqlConnectn class should be SqlConnect.
In the Program class, you need to use an instance of the SqlConnectn class to call the SqlConnect method. Try to use this:
namespace xxx
{
internal class Program
{
static void Main(string[] args)
{
SqlConnectn conn=new SqlConnectn();
SqlConnection sqlConnection = conn.SqlConnect();
}
}
public class SqlConnectn
{
public SqlConnection SqlConnect()
{
string connectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True";
SqlConnection Conn = new SqlConnection(connectionString);
return Conn;
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.