Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error / System.Data.SqlClient.SqlException (0x80131904):

0

I am developing my knowledge in n tier architecture for asp.net core 2.1. For n tier architecture knowledge I am using a website from here. For creating a database and stored procedure table I am using website from here.

Problem - When the application requesting the local host page following error appears...

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled exception has occurred while executing the request.

System.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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid.

I tried various connection string i.e

private static string CONNECTION_STRING = @"Data Source=(LocalDb)\\MSSQLLocalDB;Database=NewDB.mdf;";

and

private static string CONNECTION_STRING = "Server=(LocalDb)\\MSSQLLocalDB;Integrated Security = true; 
Database=|DataDirectory|\\NewDB.mdf;";

and

private static string CONNECTION_STRING = @"Data Source = (LocalDB) 
\\MSSQLLocalDB;AttachDbFilename=C:\\...NewDB.mdf;Integrated Security = True;

Didn't make any difference.

On the website the author does something like this...

private static string CONNECTION_STRING = @"Server=DESKTOP-PPD5M0F\SQLEXPRESS;Database=northwind;User Id=northwind_reader;Password=northwind_reader;";

So my database and table is different to the authors.

and for the CustomersRepository class my looks like this...

 public static List<Customer> GetAllCustomers()
    {
        List<Customer> retList = new List<Customer>();
        using (SqlConnection conn = new SqlConnection(SQLHelper.ConnectionString))
        {
            SqlDataReader dr = SQLHelper.ExecuteReader(conn, System.Data.CommandType.Text,
                @"SELECT [EmployeeId],[Name] FROM[NewDB].[mdf].[Table1c]", null);
            while (dr.Read())
            {
                Customer c = new Customer();
                c.EmployeeId = System.Convert.ToString(dr[0]);
                c.Name = System.Convert.ToString(dr[1]);
                retList.Add(c);
            }
        }
        return retList;

I'm using localDB so I don't have SQL developer edition or express edition.

I previously asked this question which I deleted because what I described then was different to what the problem is as advised. Also it looks more tidy. Thus adding more tags.

Thanks if anyone can help me here.

c#
sql-server
visual-studio
localdb
asp.net-core-2.1
asked on Stack Overflow Oct 23, 2018 by rs001

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0