Microsoft.Data.SqlClient CheckPoolBlockingPeriod(System.Exception) connecting to Azure Sql Database - azure-active-directory

I have a client application that connects to Azure SQL Database using AD Interactive login. It was working fine until last Friday - running the app would pop up a browser prompt for login, selecting the account would grant access appropriately. It was working fine for quite a while. Then something changed late last week and the app now throws an error when trying to connect to the database. No system patches or updates were applied to my local machine where the app is running during that time period. I confirmed that the last update applied was 4/15/2022 per Windows system settings. Seems CheckPoolBlockingPeriod is now broken? Here is the stack trace:
at Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e)
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at CsharpSqlServer.Program.Main(String[] args) in C:\Users\james.a.barnes\source\repos\dbTest\dbTest\Program.cs:line 65
Can anyone provide any insight into possible causes and workarounds? Again, the code has been running fine for a couple of months and the database connection code has not changed, so something else did. Thanks

If timeout occurs while connecting to Azure SQL Database where connection pooling is enabled, the above exception will be thrown and the login attempt fails for the next few seconds (i.e., "blocking period").
Usually, the above exception will be recovered within a few seconds.
If not, you can resolve the exception by adding ;Connection Timeout=60 to your connection string.
You can also increase the timeout seconds by replacing 60.
You can go through the below SO thread for more information:
c# - SQL Exception: Login failed for user - Stack Overflow

Related

Cannot connect to local db in .net core app via kestrel server

I'm building an API in .NET 5.0 (core) and have run into a problem connecting to a database on my local SQL server instance.
My previous projects have been ASP.Net running on IIS and issues like this have been typically resolved by changing app pool permissions etc. (I think this is a permission issue also).
The problem is I have no idea how to resolve this when the app is running using the Kestrel web server so there is no 'IIS app pool' thing that I know of to change.
I can connect to the database via VS and SMSS, and I've used the formers connection string in my application yet no matter what I try I get the following error;
Microsoft.Data.SqlClient.SqlException (0x80131904): 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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
)
---> System.ComponentModel.Win32Exception (0x89C50107): Unknown error (0x89c50107)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open()
at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1082
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 725
at {app_name}.Logic.AppServices.Test.GetAllUsersTestQuery.GetAllUsersTestQueryHandler.Handle(GetAllUsersTestQuery query) in {app_path}\{app_name}.Logic\AppServices\Test\GetAllUsersTestQuery.cs:line 51
at {app_name}.Web.Controllers.TestController.GetDbTest() in {apppath}\Controllers\TestController.cs:line 46
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:-1983577849,State:0,Class:20
Working connection string in VS2019;
I think I should also note that the project started as a learning of CQRS pattern but when I realised the limitations of using EF against my existing (non EF created) database with it's stored procedures, I'm attempting to bypass EF and am using Dapper to connect directly to the database. So this is still a test though, I'm literally just doing a select * from a table for now - just to see if this will work at all.
UPDATE
Finally noticed this discrepancy and searched for the other connnection string... totally forgot about appSetting.Development.json. ARGH!!
Connection string in appSettings.json;
Connection string being used by .Logic project;
So I fixed that but now I get a login error for user blank. Hmm...
Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user ''.
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open()
I had suspected this might be an issue all along however, why can I not connect anonomously like VS appears to do?
This BTW is running in debug mode under VS2019 using the Kestrel server. From what I can see in Task Manager it's running under my account so should have full admin rights.
UPDATE 2
Found the issue, I needed to set "Integrated Security" back to True on my connection string, reversing an earlier change for debugging purposes to see what would happen.
Ok, first things first, thank you #devon for pointing me in the right direction with that simple question "How are you passing your connection string in your application?".
That was enough to trigger some further debug steps I should have done earlier.
The solution was - the simple thing - doh!;
I had forgotten about the appsetting.Development.json sub file, so conveniently hidden away there in the UI by default. That's where the actual connection string my app was using was defined - and no I do not recall filling that out - but it has been a few weeks since I started this process and I've been away from it for a few weeks due to life.
Then in the process of trying things out to resolve the connection issue I had changed the Integrated Security property on my Connection String to false to see what would happen. I didn't expect it to help, but I also intended to change it back but forgot. A good lesson there.

Error 'Could not open a connection to SQL Server' while upgrading database with codefluent pivot runner

We use the pivot runner to update our databases. Since a year we regularly receive error message below. The database server is available, and is hardly used by other processes. After restarting, the same message usually reappears several times, but not always with the same action. As soon as we have managed to update the first database, updating the other (40+) databases also runs smoothly.
Any idea what could be the cause of this?
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The ser
ver 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: N
amed Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential
, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, Session
Data reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderMa
nager)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbC
onnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOpti
ons userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOpti
ons, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskComple
tionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at CodeFluent.Runtime.Database.Management.Database.GetSchema(String collectionName, String[] restrictionValues)
at CodeFluent.Runtime.Database.Management.SqlServer.Key.Construct(DataRow row)
at CodeFluent.Runtime.Database.Management.Key..ctor(Table table, DataRow row)
at CodeFluent.Runtime.Database.Management.SqlServer.Table.NewKey(DataRow row)
at CodeFluent.Runtime.Database.Management.SqlServer.Table.GetKeys()
at CodeFluent.Runtime.Database.Management.Table.get_Keys()
at CodeFluent.Runtime.Database.Management.Database.ResolveReferencingKeys(Boolean refresh)
at CodeFluent.Runtime.Database.Management.Table.get_ReferencingForeignKeys()
at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.<GetConstraintReferencingKeys>d__6.MoveNext()
at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.DropConstraint(String tableSchema, String tableName, String constraintName, DistinctDictio
nary`1 constraints)
at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.DropConstraint(String tableSchema, String tableName, String constraintName)
at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.UpdateColumn(PivotRunnerColumn column, Column existingColumn)
at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.UpdateTable(PivotRunnerTable table, Table existingTable)
at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.Run()
Difficult to say without the model and the databases. However if it used to work (so assuming the connection string is correct, SQL protocol still enabled, same machine and no change of permissions on the DB for the user) and if the error is not always on the same update step, it may be related to a previous timeout on some DB action, or a previous action not yet finished : for instance a previous index added not yet fully populated or reindexed. It can happen on growing database.
Another reason may be a job task running, like a backup.
Before launching the PivotRunner tool, ensure with Management Studio there is no other running/blocking transactions in progress or not too many opened connections to this DB from previous run/tests (sp_who)
My 2 cents.

How to fix System.Data.SqlClient.SqlException : "Login failed for user "xx\xxxx$""

I ran a web app on IIS and I got a
System.Data.SqlClient.SqlException: "Login failed for user'domain\account$'".
This is a exception when the function DbMigrator.Update() is called
private readonly DbMigrationsConfiguration<MyContext> _config;
public ContextInitializer(string connectionString)
{
_config = new Configuration()
{
TargetDatabase = new DbConnectionInfo(connectionString, "System.Data.SqlClient")
};
}
...
public void InitializeDatabase(MgmtStudioContext context)
{
var migrator = new DbMigrator(_config);
migrator.Update();
}
And here is the stack trace:
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\r\n
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)\r\n
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)\r\n
at System.Data.SqlClient.SqlConnection.Open()\r\n
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)\r\n
at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()\r\n
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()\r\n
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n
at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)\r\n
at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)\r\n
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)\r\n
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)\r\n
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)\r\n
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)\r\n at
Here is my connection string:
Data Source=(local);Initial Catalog=myTable; Integrated Security=True;
The code works fine in other machine, but in my computer it doesn't work and I can't find out the root cause.
According to the error message, the account 'domain\account$' does not have access to the myTable database.
I suggest you could firstly use the SQL server management system's security to check he account 'domain\account$' does not have access to the (local) server's myTable database.
More details, you could refer to this answer.
Update:
As far as I know, if you want to access SQL Server Using Windows Integrated Security. You should firstly make sure your IIS server and the sql server is inside the same intranet and use the same domain.
Then I suggest you could make sure you have set the right application pool identity account which has the permission to access the sql database.
1.You should the domain account "domain\account" in sql server to make sure it has the read and write permission
2.On IIS, open Application Pool settings.For Identity option, choose "Custom Account". Enter your username domain\account) and password.
Then it will work well.
Please, check the iispool user has permissions to log in to database. You can do this using the Microsoft Sql Server Management Studio.
I usually forget it! I Hope its helps you! Greetings.

WCF hosted on IIS (uses MSMQ) cannot connect to SQL server

I'm moving existing test environment (hosted on Azure) into new BizSpark Azure subscription.
In old setup, I had API, WCF and SQL Server hosted on same VM. The new configuration is:
API and WCF on VM1 (subscription 1)SQL Server on VM2 (subscription 2)
API works 100%, everything is good.
WCF cannot connect to the database (hosted on VM2).
The exception is:
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. ---> System.Runtime.InteropServices.COMException: The MSDTC transaction manager was unable to push the transaction to the destination transaction manager due to communication problems. Possible causes are: a firewall is present and it doesn't have an exception for the MSDTC process, the two machines cannot find each other by their NetBIOS names, or the support for network transactions is not enabled for one of the two transaction managers. (Exception from HRESULT: 0x8004D02A)
at System.Transactions.Oletx.ITransactionShim.Export(UInt32 whereaboutsSize, Byte[] whereabouts, Int32& cookieIndex, UInt32& cookieSize, CoTaskMemHandle& cookieBuffer)
at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
--- End of inner exception stack trace ---
at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at OCS.Web.DocumentGeneration.Ticketing.TicketGenerators.TangibleTicketGenerator.GenerateDocuments(GenerateDocumentsRequest generateDocumentsRequest) in c:\Projects\OCSSvrBase\OCS.Web.DocumentGeneration.Ticketing\TicketGenerators\TangibleTicketGenerator.cs:line 103
at OCS.Web.DocumentGeneration.Ticketing.TicketGenerator.GenerateDocuments(GenerateDocumentsRequest generateDocumentsRequest) in c:\Projects\OCSSvrBase\OCS.Web.DocumentGeneration.Ticketing\TicketGenerator.cs:line 111
I've spent more than a week to resolve this. I've been trying:
to setup Firewall and MSDTC on a way that I found on a few different posts
to create exactly the same settings as I have on LIVE (LIVE configuration is the same, with one difference, both VMs are under the same Azure subscription)
Any idea where I need to look at? My guess is that I'm missing something around MSMQ settings. This is just a guess, based on a fact that my API works perfectly fine (hosted on same VM1).
Thanks in advance!

error with import Export wizard sql-server

I am using SQL-server 2012. I have a large excel file about 200 MB in size. I normally Import data from excel file to sqlserver by using sql-server management studio (by selecting database->Tasks->Import data) then selecting microsoft excel as datasource.
I have noticed several times whenever i use any excel file more than 100MB I gets this error
TITLE: SQL Server Import and Export Wizard
The operation could not be completed.
ADDITIONAL INFORMATION:
Unexpected error from external database driver (ڟ珉⒀珉Ɇ 䠠⁖). (Microsoft Office Access Database Engine)
BUTTONS:
OK
here are technical details which i don't even know what it is
===================================
===================================
Unexpected error from external database driver (ڟ珉⒀珉Ɇ 䠠⁖). (Microsoft Office Access Database Engine)
Program Location:
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at Microsoft.SqlServer.Dts.DtsWizard.DTSWizard.GetOpenedConnection(WizardInputs wizardInputs, String connEntryName)
at Microsoft.SqlServer.Dts.DtsWizard.Step1.OnLeavePage(LeavePageEventArgs e)
is there any other way to import data or sugession of any application that can do data insert for me
Another way to import the data is to save the Excel file as a Comma Separated Values (.csv) format. Then import the .csv file. This simplifies the import process and allows you to get past any Excel specific issues.

Resources