Na studiach podyplomowych uczę się podstawowych zagadnień z baz danych SQL. Podczas realizacji programu spotkałem sie z problemem pobrania danych z serwera za pomocą VisualStudio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
namespace ConnectionExample
{
internal class Program
{
static void Main(string[] args)
{
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "IS\\INSTANCE4";
builder.InitialCatalog = "ShopDB";
builder.IntegratedSecurity = true;
using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) {
Console.WriteLine("\n Products Table");
Console.WriteLine("==========================================\n");
String sql = "SELECT ProductName FROM Products";
using (SqlCommand command = new SqlCommand(sql, connection)) {
connection.Open();
using (SqlDataReader reader = command.ExecuteReader()) {
while (reader.Read()) {
Console.WriteLine("{0}",reader.GetString(0));
}
}
}
}
}
catch (SqlException e) {
Console.WriteLine(e.ToString());
}
Console.ReadLine();
}
}
}
Zdjecia z konsoli i programu znajdują się tutaj:
https://gist.github.com/ireneuszszajna-cyber/ed162b516a10507c20cadad91e987861?permalink_comment_id=6007073#gistcomment-6007073
Pracuję na systemie Windows11. Baza danych została stworzona w SQL Server Management Studio 22.
Czy ktoś wie jak rozwiązać ten problem ?