question

ZhangYilang-0363 avatar image
0 Votes"
ZhangYilang-0363 asked karenpayneoregon commented

provider: SQL Network Interfaces, error: 26

I try to build the Database App in this Microsoft Walkthrough:(Simple Object Model and Query (C#)

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/walkthrough-querying-across-relationships-csharp?redirectedfrom=MSDN

In fact when I debug it it said: System.Data.SqlClient.SqlException: '在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - 定位指定的服务器/实例时出错)' like this: 93100-image.png

I try to add database on VS2019 and see the Troubleshooting section of Learning by Walkthroughs . but it still not works. I opened SQL Server(MSSQLSERVER), and also open TCP/IP and Names Pipes. I also make a rules to allow use 1433 on firewall.


I have no idea to solve this problem, any suggestions? Or I need to connectionString on App.config? Even if in LINQ to SQL? Is so here is my connectionString
93184-image.png

and how to add it?

And I felt. Mircosoft docs missing some steps....


sql-server-generaldotnet-csharpvs-generalvs-debugging
image.png (79.0 KiB)
image.png (29.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered karenpayneoregon commented

Your connection string should be as follows if using SQL-Server Express edition

 Server=.\SQLEXPRESS;Database=NorthWind;Integrated Security=true

The connection string may be stored in app.config or if using .NET 5 in appsettings.json

 {
 "database": {
 "DatabaseServer": ".\\SQLEXPRESS",
 "Catalog": "NorthWind2020",
 "IntegratedSecurity": "true",
 "UsingLogging": "true"
 },
 "ConnectionStrings": {
 "DevelopmentConnection": "Server=.\\SQLEXPRESS;Database=NorthWind2020;Integrated Security=true",
 "ProductionConnection": "Server=.\\SQLEXPRESS;Database=NorthWind2020;Integrated Security=true"
 },
 "Environment": {
 "Production": false
 }
 }

Now with that understood see my code samples, one uses Entity Framework Core (preferred) while the other uses a data provider. Both use the same connection string under ConnectionStrings -> DevelopmentConnection were Environment specifies prod or dev (yes both are the same but in a real app they would be different.

The database for the code sample is a modified version of the original NorthWind which I created in 2020 hence 2020 appended to the catalog name.

Here is the database script.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

No, I using .Net Framework

0 Votes 0 ·

Does not matter, .NET Framework and .NET Core Framework work the same. Only difference in my code samples is the using statement devoid of Bob Hope brackets {}

0 Votes 0 ·

And I use SSMS.

0 Votes 0 ·

Same here


93144-f1.png


0 Votes 0 ·
f1.png (47.5 KiB)