Sql Server Connection via EF - c#

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" />

Related

Cannot connect to ASP.NET database

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'

Cannot connect to LocalDB, file not found exception

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.

Connection String to SQL Server 2014 Failing

A developer friend and I could not get a connection string to work on my PC.
I'm calling to a local db instance which is Management Studio 2014 (one of the free editions).
It fails on connection.Open();
The Code is:
string conn = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ToString();
IDbConnection connection = new SqlConnection(conn);
connection.Open();
App.Config is:
<connectionStrings>
<add name="DatabaseConnection"
connectionString="data source=MIKE-PC; initial catalog=dbname;integrated security =True"
providerName="System.Data.SqlClient" />
</connectionStrings>
The Error is:
An unhandled exception of type 'System.Data.SqlClient.SqlException'
occurred in System.Data.dll
Additional information:
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)
There are many possible issues that you can check to correct this:
Make sure your database server is running: open run or shortcut Window + R, type services.msc, hit enter. Make sure the SQL Server (SQLEXPRESS) service is running.
Open your SQL Management Studio. Try to connect to your database from there to make sure your server name (data source) and database name (initial catalog) are correct.
Make sure your database can be accessed using Integrated Security. You can tell that it does if you can connect to your database using "Windows Authentication" from your MS SQL Server Management Studio.
Hope this help.

Connection String Error after uploading on Godaddy (ASP.NET)

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>

error while Connecting .mdf database

I developed a small project in visual studio 2010. In my project I attach a service-based database named database1.mdf.
My connectionString is :
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True
It works fine on my developer pc but it throws an exception on a client's pc.
Exception 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)
I don't understand what is happening.
Two things need to occur before you can connect to a SQL Server Express database.
SQL Server Express must be installed on the target server. Having the file present isn't sufficient. (This is what the error you're experiencing likely means).
The path to your database file should be an absolute path to rule out the possibility of a file location error.
this connection string is for your developer machine. you share your database on the network. you also must update your connection string by adding ip address of your server.

Categories

Resources