2
Good people, I’m new in c# and then I’m seeing some tutorials connecting to the database only that this error appears to me:
The code I made is all still based on a basic tutorial and I leave it here for you to see
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace teste
{
class Program
{
static void Main(string[] args)
{
SqlConnection connection = new SqlConnection("Server=.\\SQLEXPRESS;Database=teste; Integrated Security = true");
{
connection.Open();
//
// The SqlCommand should be created inside a using statement.
// ... It receives the SQL statement as the first argument.
// ... It receives the connection object as the second argument.
// ... The SQL text only works with a specific database.
//
using (SqlCommand command = new SqlCommand(
"SELECT TOP 3 * FROM my_cab",
connection))
{
//
// Instance methods can be used on the SqlCommand instance.
// ... These read data from executing the command.
//
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine(reader.GetValue(i));
}
Console.WriteLine();
}
}
}
}
}
}
}
What’s wrong with it? Thank you
You have installed SQL Server Express on your machine?
– Leonel Sanches da Silva