EF4 EntityException - The underlying provider failed on Open - asp.net-mvc-2

Okay, this is a new one. I'm trying to debug my project, which I've done many times in the past, and I'm now getting this exception in one of my repositories. I haven't seen it before now. I haven't touched my repos in days, and my connection string is the same as its always been. The inner exception states:
{"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)"}
And the code it's choking on is:
public class HGArticleRepository : IArticleRepository
{
private HGEntities _siteDB = new HGEntities();
public List<Article> Articles
{
get { return _siteDB.Articles.ToList(); } // <-- this is the line
}
// more repo code
}
Again, like I said, I've never encountered this exception before, and I haven't touched my domain code in days.

This error usually means:
Connection String points to nonexistent SQL Server.
Connection String points to SQL Server that was shut down. Or not started.
Named pipes transport was disabled in SQL Server settings.
Check them carefully one by one. In your case I guess it is 2.

A second option of solution:
Review that IIS is running.
In my case it was stopped, so I got the same error.

Related

Delphi failover needs to reconnect to the database

I was trying to implement the failover available here
http://www.andreanolanusse.com/en/implementing-failover-and-load-balancing-in-datasnap-2010/
but if I add a database connection and kill the first server, when I use some of the remote functions or '.open' a TClientDataSet 2 times, it throws an exception and I need to reconnect to the database again.
Expected: '{' found: '-+0-9.' at position: 84
{"result":[{"rows":[0]},{"data":[44,#192#16#0(nabas - (Server 213) pacote36-trafegusgr]}]}#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
(the error message contains about 23000 of those '#0')
It works if I reconnect but when you have to implement in a system that have hundreds of '.open' and remote method calls it isn't the best option.
And since the error is only thrown the second time I click the button and call the method, it looks like it doesn't need to reconnect, it must be something I'm doing wrong.
Here's the project:
https://drive.google.com/file/d/0B6YhWGZN7O24Zl9pYkx6d3hrdDA/view?usp=sharing
it uses the postgresql connection from devart (DevartPostgreSQL)

Hang in System.Data.Entity.DbSet.Add()

I am following the Create an OData v4 Endpoint Using ASP.NET Web API 2.2 sample, and the Post() method implementation looks like this:
public async Task<IHttpActionResult> Post(Product product)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Products.Add(product);
await db.SaveChangesAsync();
return Created(product);
}
However, when a Post request is received, Products.Add() hangs and never returns. No exception is thrown.
Under WinDBG I can see the following callstack:
System.Threading.Thread.Sleep
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist
System.Data.SqlClient.SqlInternalConnectionTds..ctor
System.Data.SqlClient.SqlConnectionFactory.CreateConnection
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection
System.Data.ProviderBase.DbConnectionPool.CreateObject
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest
System.Data.ProviderBase.DbConnectionPool.TryGetConnection
System.Data.ProviderBase.DbConnectionPool.TryGetConnection
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection
System.Data.SqlClient.SqlConnection.TryOpenInner
System.Runtime.InteropServices.SafeHandle.Dispose
System.Data.SqlClient.SqlConnection.TryOpen
System.Data.SqlClient.SqlConnection.Open
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute
System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection
System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection
System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked
System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo
System.Data.Entity.DbModelBuilder.Build
System.Data.Entity.Internal.LazyInternalContext.CreateModel
System.Data.Entity.Internal.LazyInternalContext.InitializeContext
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType
System.Data.Entity.DbSet.Add
ProductService.Controllers.ProductsController.Post
I am using EntityFramework 6.1.3.
If the Add() method is the one creating the connection with the database, should it be an *Async() method?
Update:
After porting the code from ASP.NET to Console Application, I caught the following exception:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
The problem is that the tutorial connection string is not valid anymore for Visual Studio 2015; Data Source=(localdb)\v11.0 needs to be replaced with Data Source=(localdb)\mssqllocaldb.
I.e.:
<add
name="ProductsContext"
connectionString="Data Source=(localdb)\mssqllocaldb;
Initial Catalog=ProductsContext; Integrated Security=True;
MultipleActiveResultSets=True;
AttachDbFilename=|DataDirectory|ProductsContext.mdf"
providerName="System.Data.SqlClient" />

No connection could be made because the target machine actively refused it 127.0.0.1:25

I get this error while running web services using a web application.
No connection could be made because the target machine actively refused it 127.0.0.1:8083
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8083
Source Error:
Line 108: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/VerifyFingerPrint", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 109: public string VerifyFingerPrint([System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] VeriBmp, string empcode) {
Line 110: object[] results = this.Invoke("VerifyFingerPrint", new object[] {
Line 111: VeriBmp,
Line 112: empcode});
Source File: D:\Mayuri1working\BOBFingerPrint\BOBFingerPrint\Web References\localhost\Reference.cs Line: 110
Please help !
First update your web service references used in your application.
If web service references are not get updated, then check all files and folder containing source code files in your web service project solution and rebuild it and then update web references used in your project.
Else if its working fine then you need to check your network services used by your development server and windows firewall settings as suggested in above solutions.
I also encountered same problem and I came to know that I was referencing wrong folder having same name but used in another solution.
Enjoy codding.

Mobile Services (.Net backend) using incorrect connection string

I am struggling to make the .Net backend of Mobile Services use the correct connectionString. When I publish the service I select the correct connection string for "MS_TableConnectionString". If I check the web.config on the server (via FTP) I see what I would expect:
web.config on server:
<connectionStrings>
<add name="MS_TableConnectionString" connectionString="Data Source=tcp:[ServerAddress].database.windows.net,1433;Initial Catalog=[MyMobileService_db];Integrated Security=False;User ID=[correctUserName];Password=[CorrectPassword];Connect Timeout=30;Encrypt=True" providerName="System.Data.SqlClient" />
In my context it is configured to use a connection string called MS_TableConnectionString:
private const string connectionStringName = "Name=MS_TableConnectionString";
public MyMobileServiceContext() : base(connectionStringName)
{
Schema = "MyMobileService";
}
To see what connection string is actually being used I added this to an example controller:
Example Client Code:
public class ExampleController : ApiController
{
MyMobileServiceContext context;
public ApiServices ApiServices { get; set; }
public ExampleController()
{
context = new MyMobileServiceContext();
}
public async Task<IHttpActionResult> PostExample(ExampleItem item)
{
ApiServices.Log.Warn("ConnectionString: " + context.Database.Connection.ConnectionString);
...
}
And when I look at the Log Entry on Mobile Services I see a different UserName and Password:
[2014-04-15T12:26:33.1410580Z] Level=Warn, Kind=Trace, Category='PostExampleItem', Id=00000000-0000-0000-0000-000000000000, Message='ConnectionString: Data Source=[SameServerAddress].database.windows.net;Initial Catalog=[SameDatabaseName];User ID=[DifferentUserName];Password=[DifferentPassword];Asynchronous Processing=True;TrustServerCertificate=False;'
The different username and password are the same as I see in the original .PublishSettings file that I downloaded under the name of SQLServerDBConnectionString but I have no idea where this is stored on the server?
Because of the different username and password I see the following exception in the log:
[2014-04-15T13:18:11.2007511Z] Level=Error, Kind=Trace, Category='App.Request', Id=d7ec6d25-f3b7-4e88-9024-217be40ae77f, Exception=System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: Cannot open database "master" requested by the login. The login failed.
Login failed for user '[DifferentUserName]'.
This session has been assigned a tracing ID of '[GUID]'. Provide this tracing ID to customer support when you need assistance.
Any help would be much appreciated as at the moment I am having to hard code the whole connection string in the constructor of the Context to make it work.
Thanks
F
UPDATE: 15th April 2014 15:23
I deleted all my publisher profiles and created a copy of the original .PublishSettings file. From this I deleted all but one profile. I then deleted the SQLDBConnectionString attribute to confirm that it is not because I was sending this that was causing the problem. The result was no change, it is still using the DifferentUserName and Password so it must be reading it from the server somewhere.
We have a hole at the moment in that we pick up the connection string from the portal yet don't expose the ability to set or modify connection strings there.
The work-around is to set an application setting in the portal and then use that in your code using the ApiServices class, something like this (in your controller)
string connectionString = this.Services.Settings["YourConnectionStringAsAppSetting"];
I know it is confusing... we'll make it easier to access and modify the connection strings.
Henrik

Jboss shows error with datasource on startup

On starting jboss I am getting the following error :
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.jca:service=DataSourceBinding,name=DefaultDS
State: NOTYETINSTALLED
Depends On Me:
jboss.ejb:service=EJBTimerService,persistencePolicy=database
jboss:service=KeyGeneratorFactory,type=HiLo
jboss.mq:service=StateManager
jboss.mq:service=PersistenceManager
And for all database connections in the servlet I get the following exception :
org.postgresql.util.PSQLException: FATAL: password a
uthentication failed for user "poll"
It was working fine and all of a sudden I started getting these errors. My password is correct. I even tried changing the password and then tried again it showed the same exception. What is happening here?
The DefaultDS data source is what the name suggests; the default datasource. It ships with JBoss and is configured to use the Hypersonic (ie in-memory) database. JBoss uses the DefaultDS datasource to read/write internal queues, timed events, etc
Check the file ../conf/standardjbosscmp-jdbc.xml to see what you've got configured for the DefaultDS datasource. It sounds like you've edited that file unintentionally. Unless you need to persist internal queues etc across boots, just leave it as shipped using Hypersonic.
See the JBoss doc for more.