I am trying to connect my project in visual studio to my database using SQL Server 2012. this is my code :
public class DatabaseConnection
public static SqlConnection Con;
public static SqlConnection GlobalConnection()
string ConString = @"Data Source=DESKTOP-JTVC4I1\\SQLEXPRESS;" + Global.ServerName + ";Initial Catalog=College" + Global.Database + ";Integrated Security=True;User Id=sa" + Global.SUserId + ";Password=123" + Global.SPassword + ";Connection Timeout=1000";
Con = new SqlConnection();
Con.ConnectionString = ConString;
if (Con.State == ConnectionState.Open)
A Network-related or instance-specific error occurred when
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections.
Your connection string's
Integrated Security=True. This means the
User Id and
Password attributes you specified will be ignored and the current Logged Windows Identity will be used.
Try changing your connection string to
More details can be found at MSDN SqlConnection.ConnectionString Property
When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true. If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used.