I have a SQL Server Express installed on ULTIMATE03
running Windows 10. Visual Studio 2022 is running a console application. That console application fails to connect to the ULTIMATE03
machine. SQL Server Express server name is also ULTIMATE03
.
using System;
using System.Linq;
using System.Data.SqlClient;
using System.Diagnostics;
namespace ConnectSQLExpress
{
class Program
{
public static SqlConnection GetConnectionsString()
{
string x = "Server=ULTIMATE03\ULTIMATE03;Trusted_Connection=True;" +
"Database=master;" +
"Integrated Security=SSPI;" +
"User Id = gmort; Password=gm6301" +
"Connection timeout=30;";
return new SqlConnection(x);
}
static void Main(string[] args)
{
using (SqlConnection myConnection = GetConnectionsString())
{
try
{
SqlCommand myCommand = new SqlCommand("SELECT COUNT(*) FROM GAMESINFO " + "Values ('string', 1)", myConnection);
System.Diagnostics.Debug.WriteLine("ee");
myConnection.Open();
myCommand.ExecuteNonQuery();
SqlDataReader myReader = null;
myCommand.CommandText = "select * from students";
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine(myReader["firstname"].ToString());
Console.WriteLine(myReader["age"].ToString());
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
}
}
}
Getting error 26 consistently (shown below)
New contributor
Lightbulb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5