question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UWP & Standard Library 2.0

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
OrangeProwlercommented, Nov 8, 2017

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

0reactions
saurabh500commented, Nov 7, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing UWP Support for .NET Standard 2.0
.NET Standard is a specification of APIs that all .NET implementations have to implement. UWP now has support for .NET Standard 2.0. The...
Read more >
Share code between a desktop application and a UWP app
NET Standard 2.0 class libraries, and then create a UWP app that references your .NET Standard 2.0 libraries. Share code in a .NET...
Read more >
How can I reference a .NET Standard 2.0 class libary from ...
NET Standard 2.0 class library from my Universal Windows app. How can this be? Does Microsoft really expect that if I were to...
Read more >
UWP can't reference .Net Standard 2.0 projects?? (#462)
Just create a UWP project and reference a .NEt Standard 2.0 library and you get: Project 'MyStd20Lib.csproj' targets '.NETStandard,Version=v2.0' ...
Read more >
What Is The Future of UWP In .NET Standard 2.0
In this video, Stott Hunter, Miguel De Icaza, and Tim Heuer discuss the future of UWP, XAML and support of .NET Standard 2.0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found