I don't know how to connect to my SQL Server (local) from an application on ASP.NET MVC.
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: 26 - Error Locating Server/Instance Specified)
Connect to SQL SERVER (DbSetttings.json)
{
"ConnectionStrings": {
"DefaultConnection": "Server=СМОЛЬКИНСЕРГЕЙ\\SERVER;Database=Shop;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Making creation through ef migrations
EntityFrameworkCore\Add-Migration initial
EntityFrameworkCore\Update-DataBase
enter image description here
I am new and can not understand what the error is
Have you tried changing the connection string as follows:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=СМОЛЬКИНСЕРГЕЙ\\SERVER;Initial Catalog=Shop;Trusted_Connection=True;MultipleActiveResultSets=true"
}
Notice 'Server' and 'Database' are changed 'Data Source' and 'Initial Catalog'
Related
SQL Server is running over TCP/IP.
When I try to first update-database
PM> update-database
Build started... Build succeeded. ...........
ClientConnectionId:00000000-0000-0000-0000-000000000000 Error
Number:-1,State:0,Class:20 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: SNI_PN11, error: 26 - Error Locating
Server/Instance Specified)
Firewall is correct, rules are added for ports 1433, 1434, 55120.
I have a connection in Visual Studio to SQL Server The connection string in appsettings.json is:
"ConnectionStrings": {
"ProductionManagmentContext": "Server=DESKTOP-MAQO344\\SQLEXPRESS;Database=ProductionManagment.Data;Trusted_Connection=True;MultipleActiveResultSets=true"
I have a .NET Core application as API. I can connect it to a local SQL Server database, but not to other databases on my network.
When I try to access a remote database using a dbContext, I get this error:
System.Data.SqlClient.SqlException:
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: 26 - Error Locating Server/Instance Specified)
appsettings.json for local:
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=ib;Integrated Security=True;"
}
appsettings.json for remote:
"ConnectionStrings": {
"DefaultConnection": "Server=[servername]\[instanz];Database=IBCore_Lange;User Id=sa;password=XXX"
}
I can access the database via SQL Server Management Studio, or a previous (ASP.NET) version of my system. In Core, I can only access to a local database.
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
services.AddDbContext<ibContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
The DbContext is generated:
Scaffold-DbContext "Connection String"
Microsoft.EntityFrameworkCore.SqlServer -Verbose -o {output folder} -t {table to update} -force
Try following:
Make sure TCP/IP protocol enabled via SQL Server configuration manager. Also, ensure the custom port not configured, for detailed info
Do telnet HC-SERVER-04 1433 from command prompt of the remote host (from where you tried to connect SQL server)
If Step 2 fails: Create rule in Firewall of the SQL Server with port# 1433 and 1434 to accept incoming connections, then try again telnet, if telnet works, application should be able to connect
If doesn't work after firewall entry: Restart SQL Browser service
No Luck with SQL Browser service, change connection string as follows:
Server=HC-SERVER-04,1433;Database=IBCore_Lange;User Id=sa;password=XXX
In json file, put double \\ like "DefaultConnection": "Data Source=db-name\\test2019; ...
The Problem here is the named instance of the server "Server=[servername]\[instanz]".
I can connect to a SQL-Server without a instance.
I did not found a solution for Servers with named instances yet.
Although I can connect to the server when I'm using either legacy SqlConnection or Sql Management Studio, I'm not able to make connection to Sql Server via Entity framework. In addition I've check all following things:
Data Source or Server Name or IP address is correct. it is: SKI-PC\
I'm sure that my instance name is correct.
Remote connections are allowed and also there is no firewall.
The error I'm facing is:
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: 26 - Error Locating Server/Instance
Specified)
Just for clarifying, my connection string in app.config is:
<add name="MyEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SKI-PC\SEP;initial catalog=Restaurant;user id=sa;password=;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
here is the connection string
<add name="Tapo_ModelContainer" connectionString="metadata=res://*/filename.csdl|res://*/filename.ssdl|res://*/filename.msl;provider=System.Data.SqlClient;provider connection string='Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=APTapo;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework'" providerName="System.Data.SqlClient" />
The Exception
System.Data.EntityException {"The underlying provider failed on Open."}
inner Exception
"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
inner exception
"The system cannot find the file specified"
If i use the normal SqlConnection class, i can connect to the database.
It could be because of the permissions.
in the Authentication section. If you can not write the correct connection string you can use Connect To Database option in Tools menu item and if Test Connection is ok then copy the connection string.
I have created a login application using ASP.NET and SQL Server. It runs perfectly on my localhost but as soon as I uploaded it on GODADDY, I got the ERROR regarding the connection string.
I have also changed the connection string with the one provided by GODADDY but it did not work.
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: 26 - Error Locating Server/Instance Specified).
Exception Details: System.Data.SqlClient.SqlException: 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: 26 - Error Locating Server/Instance Specified)
I have made DLL and BLL namespaces to which i gave reference of my asp.net application.
I have used connection string in two files (1) in DLL/clsdll.cs file (2) in web.config file as follows
Connection String in clsdll.cs file :-
con = new SqlConnection("Data Source=XXXX;Integrated Security=False;User ID=ZZZZZ;Password=YYYYY;Initial Catalog=demo1;Connect Timeout=15;Encrypt=False;Packet Size=4096");
Connection String in WEB.CONFIG file :-
<connectionStrings>
<add name="SampleConnectionString"
connectionString="Data Source=XXXX;Integrated Security=SSIP;User ID=ZZZZZ;Password=YYYYY;Initial Catalog=demo1;Connect Timeout=15;Encrypt=False;Packet Size=4096"/>
</connectionStrings>
The connection string above is the one provided by GODADDY but it doesn't work.
Can anyone help me out with this please....
only this much info is required you can remove the rest and try once
data source=XXXX;user id=XXXX; password=XXXX; initial catalog=XXXX;
Well, in your web.config, you have both the "Integrated Security" (with a spelling typo - it should be Integrated Security=SSPI) as well as an explicit username/password.
Don't do that - either you use integrated security (unlikely, in a hosted environment), or then you use user ID=.../Password=... - but don't enable BOTH at the same time!
In your case, I would try
<connectionStrings>
<add name="SampleConnectionString"
connectionString="Data Source=XXXX;Initial Catalog=demo1;User ID=ZZZZZ;Password=YYYYY;"/>
</connectionStrings>