I am using console to write a class to handle a sql server link and another class to handle a data API. But If I use the same class in a windows form, neither of those classes works, they can not set up the connection. It fails when I try to connect sql server database and also, can not setup the connection with the Data API at all.
What is different between building a C# console project and C# windows form project? How do I set up those connections? Is there any configuration I can change?
ConnectionString = "Data Source=JF-T7K5-01;Initial Catalog=" + DataBaseName +";Integrated Security=True;";
Connection = new SqlConnection(ConnectionString);
try
{
Connection.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
I would suggest that you first check framework type. I have tried both console and form, connection works on both.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.