UWP & Standard Library 2.0
See original GitHub issueI have the EF DBContext and all of it’s models, logic and the connection string in a .Net Standard Library version 2.0. I am adding this library as a reference to a UWP app targeting Build 16299. In this app I have a textblock “txtStatus” and a simple button that runs this simple function:
private void Button_Click(object sender, RoutedEventArgs e)
{
txtStatus.Text = "Starting Build....";
brickContext context = new brickContext(1);
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
txtStatus.Text = "Done!";
}
On execution it generates the following error on the line “context.Database.EnsureDeleted()”.:
System.Data.SqlClient.SqlException occurred
HResult=0x80131904
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: TCP Provider, error: 25 - Connection string is not valid)
Source=Core .Net SqlClient Data Provider
StackTrace:
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
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.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, Func`2 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureDeleted()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureDeleted()
at BrickBuilder.MainPage.Button_Click(Object sender, RoutedEventArgs e) in C:\CRJD.2017\APP\GuyWash\BrickBuilder\BrickBuilder\MainPage.xaml.cs:line 35
Inner Exception 1:
SocketException: The operation completed successfully
If I take that same .Net Standard Library and reference it in an blank ASP.Core 2.0 web application it and add a the following procedure:
public Initialize()
{
string txtStatus = "Starting Build....";
brickContext context = new brickContext(1);
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
txtStatus = "Done!";
}
It executes the procedure without error and generates a new database in the SQL Server. I am trying to understand why it won’t work in UWP and doesn’t seem to be able to connect to the server in the same way it works in the web app. I have checked that that the “enterpriseAuthentication” is enabled in the package manifest. Am I missing something else in the manifest? I have also tried to run this with SQL Lite instead in UWP and that does seem to work. Thanks. Chris
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
TCP was not enabled. I did enable the protocol but it did not fix the problem. I have the Windows 10 Fall Creator Update and have set my target and minimum build to 16299. I does look like I have a different error now: I also verified that my Server Properties has Allow remote connections to this server enabled. Also, I verified again that the same library with the same connection string works when using it in an asp.net core web app.
I did some further research and I did notice an error regarding port 1433. I adjusted my firewall and it finally seems to be working correctly. Thanks again for all of your help.
Chris
@ajcvickers We added this as part of .Net Core UWP effort. This should be available with Windows 10 Fall Creators Update. As @ErikEJ mentioned, there are capabilities that need to be enabled for networking. @OrangeProwler Is TCP enabled on Sql Server? Also are you using the Windows 10 Fall Creators Update? You could create a TCP client to connect to the SQL server port and try to open a TCP connection. By default the port is 1433. This should help narrow down the issue.