Adam
Adam
CC#
Created by Adam on 5/22/2024 in #help
Trouble Connecting to Database
I'm using Dapper and SqlClient but I keep getting this error: Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while 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. (provider: TCP Provider, error: 35 - An internal exception was caught) here is the code:
using System.Data;
using Dapper;
using Microsoft.Data.SqlClient;

namespace MacBlazor2
{
public class DbHelper
{
private IDbConnection connection;

public DbHelper() {
connection = new SqlConnection("User ID=postgres;Password=password;Server=localhost:5432;Database=dvdrental;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;");
Console.WriteLine(connection.Database);
Console.WriteLine(connection.ConnectionString);
foreach(Person p in connection.Query<Person>("SELECT actor_id, first_name, last_name FROM actor")) Console.WriteLine(p.first_name + " " + p.last_name);
}

}
}
using System.Data;
using Dapper;
using Microsoft.Data.SqlClient;

namespace MacBlazor2
{
public class DbHelper
{
private IDbConnection connection;

public DbHelper() {
connection = new SqlConnection("User ID=postgres;Password=password;Server=localhost:5432;Database=dvdrental;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;");
Console.WriteLine(connection.Database);
Console.WriteLine(connection.ConnectionString);
foreach(Person p in connection.Query<Person>("SELECT actor_id, first_name, last_name FROM actor")) Console.WriteLine(p.first_name + " " + p.last_name);
}

}
}
15 replies
CC#
Created by Adam on 5/17/2024 in #help
Error CS0234
using Microsoft.Data.SqlClient; namespace DataAccessLibrary { public class SqlDataAccess { private readonly IConfiguration _config; public string ConnectionStringName { get; set; } = "Default"; public SqlDataAccess(IConfiguration configuration) { _config = configuration; } public async Task<List<T>> LoadData<T, U>(string sql, U parameters) { string connectionString = _config.GetConnectionString(ConnectionStringName); using(IDbConnection connection = new Microsoft.Data.SqlClient.SqlConnection(connectionString)) { } return null; } } } I get the error on the Microsoft.Data.SqlClient section, I have the package reference in my .csproj here: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <PackageReference Include="Dapper" Version="2.1.35" /> <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> </ItemGroup> </Project> Any ideas on how to fix this?
10 replies
CC#
Created by Adam on 5/14/2024 in #help
Error CS0103
I am trying to follow this tutorial: https://learn.microsoft.com/en-us/training/modules/blazor-build-rich-interactive-components/2-create-user-interfaces-blazor-components?ns-enrollment-type=learningpath&ns-enrollment-id=learn.aspnet.build-blazor-webapps and I am getting error CS0103 when trying to use <div @ref="placeHolder"></div> so that "...Blazor render tree doesn't attempt to track its contents. " and I can use the DOM to act on the div.
5 replies