error 26 cannot connect to database - c#

I took an old software made by someone else, which need to connect to a database with the .mdf extension.
But when I run the software, I have an error 26. I have obviously checked Google and it seems the the main problem is the firewall. But if I disable it the problem doesn't dissapear.
Here is the code for connect the database :
DataClasses1DataContext db = new DataClasses1DataContext(Environment.CurrentDirectory + "\\bddgestionvin.mdf");
I've noticed, when I try to connect the database with the datacontext class it fail too with the same error 26. (see attached screenshot below)
The string connection used by this class is :
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bddgestionvin.mdf;Integrated Security=True;Connect `Timeout=30;User Instance=True`
I know I'm a little vague but I never did that kind of stuff (connect to a .mdf database) And the code is not mine, feel free the ask further explanation / code. Any help is welcome !
P.S The error message is
SqlException was unhandled 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)
(Sorry for the french software)

Hi I don't know you may see these steps. Make sure that these steps should pass.
The reason that we get this error message is the client stack could
not receive SSRP response UDP packet from SQL Browser. It's easy to
isolate the issue. Here are the steps:
1) Make sure your server name is correct, e.g., no typo on the name.
2) Make sure your instance name is correct and there is actually such
an instance on your target machine. [Update: Some application converts
\ to . If you are not sure about your application, please try both
Server\Instance and Server\Instance in your connection string]
3) Make sure the server machine is reachable, e.g, DNS can be resolve
correctly, you are able to ping the server (not always true).
4) Make sure SQL Browser service is running on the server.
5) If firewall is enabled on the server, you need to put
sqlbrowser.exe and/or UDP port 1434 into exception.
You can read more from here
You can also try PortQry and validate your firewall does not block SQL Browser UDP packet
A network-related or instance-specific error occurred while establishing a connection to SQL Server. Failed to establish a connection with SQL Server.
The server was not found or was not accessible.
May be server is stopped, you don't have permission to access the server, or the instance name is not correct .
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
Please goto SSMS and try connecting the server. Verify the SQL Server is running and your account is configured to access the service.
(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Thanks

Related

Add retry to LINQ2SQL queries

I have a C# application that needs to connect to a SQL Server DB hosted by Amazon's RDS. Fairly often it throws the error
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)
When it does this, it usually works on the next try. So I would like to add a programmatic "retry" to the queries in my app. I think that this (https://stackoverflow.com/a/4822976/1011724) looks like a good pattern to follow for this. However, that answer only retries for the following errors:
private enum RetryableSqlErrors
{
Timeout = -2,
NoLock = 1204,
Deadlock = 1205,
WordbreakerTimeout = 30053,
}
So is there a way to simply add this error? If so, what is the error code? Looking here (https://msdn.microsoft.com/en-us/library/cc645611.aspx), there is no error 40 and it also is not the exact wording of error -1.
Is my error a SqlException? If so what number? If not, how can I adapted the code from the answer linked above to account for this type of exception?

IIS 8.5 Web.config for named SQL Server instance on alternate port

I recently upgraded to Windows Server 2012 from 2003. It was a big IIS jump from 6 to 8.5. I cannot seem to get a named SQL Server instance on an alternate port to work in my ASP.net 4.0 website.
The connection string I am using is:
<add name="MyConn"
connectionString="Server=192.168.12.5\stage,7839;Database=mydb;uid=myun;pwd=mypw;" />
When the website tries to load in the browser, I get the following error:
[HttpException (0x80004005): 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: 0 - No connection could be made because the target machine actively refused it.)]
We've checked firewall settings to no avail. Is the syntax correct in the above example? I've done numerous searches and found examples of people using
192.168.12.5:7839\stage
or
192.168.12.5\stage;port=7839;
but both of those give syntax errors.
I need some confirmation on the correct syntax for the web.config file. Any help is greatly appreciated, thanks!
Can you go to SQL Server > Configuration Tools > Configuration Manager and see if that instance is really named what you think it is?
You should see something like this:
The entries SQL Server (instacename) on the right hand side show you what instances you have - they should be in state running, and the instance name is in the brackets. If it's MSSQLSERVER, then it's an unnamed default instance - otherwise it's the instance name. Is your instance name correct, as expected - and running?

Error creating an SQL Server Database in Visual Studio

I am trying to create a new SQL DB in Visual Studio 2010, and Upon entering a Server Name and a DB name then pressing Ok, I get this error.
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)
Any ideas?
Just go through this article.I think you can solve the problem.
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/
Also ensure you have specified servername and database name correctly in connection string.just take connection string from property window of added database.
Try this article, it goes through pretty much all the steps you will need to troubleshoot your connectivity problems:
http://social.technet.microsoft.com/wiki/contents/articles/2102.how-to-troubleshoot-connecting-to-the-sql-server-database-engine.aspx

Insert ErrorA network-related or instance-specific error occurred while establishing a connection to SQL Server

I got a error while i upload my application on server and it works fine at my localhost.
On server when doing any entry i got the following error.
Insert ErrorA 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).
and with same connection string i m using it on my localhost.
my connection string is look like
string connection = "Data Source=XXX.XXX.XXX.XXX; Initial Catalog=abcdefgh; Persist Security Info=True; User ID=ag_packers; Password=agpackers";
and when i used the same connection string in my local host it works fine and at server it gives the following error.
This could have different reasons, heres allready 2:
DataSource incorrect, if it's on the same machine try: ./SqlServerName
Your SqlServer service is not running, enable it at services.svc
Some points for you to check
Check whether your database server name/IP address is reachable from your web server by using ping dos command.
Check whether your target database is a Defaule SQL Server Instance or a Named instance. If it a named instance use this format for that.
Enable the named pipes/TCP IP for SQL server using server configuration manager.
Good luck.

Error connecting SQL server to MVC3 application - A network-related or instance-specific error

I'm getting this error since I've moved my mvc3/entity framework site onto the live server from localhost. Normally when I would get this error, I'd check the database name, password and server are all correct in the connection string. I have checked this - they all seem fine.
I have aspnet Membership provider on the site within the database, and it allows me to login, verifies me, then tries to redirect me to another page, and then that's where the error happens - i.e., as soon as I connect to the database outwith the membership provider.
The database is on the same server as the site, and when I connect from localhost to the remote server, it works perfectly.
Here is the full error message:
Exception message: 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)
Here is the connection string:
<add name="ApplicationServices" connectionString="Data Source=192.168.1.43;Initial Catalog=BlueLadder;User Id=BlueLadderAdmin;Password=Auth1991;timeout=30" />
Anyone anything I could try?
Ok, despite my connection string in the web config, it was actually being ignored and the application was still trying to connect to a local version. Apparently you need to pass the connection string through the dbContext constructor, like so.
public Context()
: base("ConnectionString")
{
}
Question was answered here
Thanks for your help anyway.
Try removing the Data Source and Initial Catalog, and replace them with something like this:
Server=.\SQLEXPRESS;Database=BlueLadder;
I don't know if you're using SQLEXPRESS, so just modify accordingly if you're not.
Check if your server is accepting remote connections and has TCP/IP provider enabled. You can configure this using "Sql Server Configuration Manager" on your server
You could try specifying the named instance of your server. "Sql Server Configuration Manager" can tell you what instances are installed on your server.
Server = 192.168.1.43/MSSQLSERVER or
Server = 192.168.1.43/SQLEXPRESS

Categories

Resources