none
[UWP][RS3:1709]Connecting UWP to SQL Database RRS feed

  • Question

  • I tried to replicate the Northwind database example presented at Ignite and it fails to connect to my SQLExpress database.

    Although the connection string points to that database ("Data Source=myPC\SQLEXPRESS; .." it does not connect. Running in debug mode I found out that the connection string actually used is different: "Data Source=(localdb)\MSSQLLocalDB;.."

    And, the error message provided: "LocalDB is not supported on this platform."

    OK, but why is it not using SQLExpress as coded in my App.xaml.cs but uses localdb not coded at all?

    I have both LocalDB (13.0.4001) and SQLExpress (14.0.1000) installed on my PC because some other programs are using LocalDB.


    Thursday, October 19, 2017 4:39 PM

All replies

  • My understanding is that only SQLite is supported by UWP.


    Sam Hobbs
    SimpleSamples.Info

    Thursday, October 19, 2017 5:16 PM
  • My understanding is that only SQLite is supported by UWP.


    Sam Hobbs
    SimpleSamples.Info


    Not longer true. You have to watch the presentation Stefan Wick and Ginny Caughey gave just recently at the Ignite conference. 
    Friday, October 20, 2017 1:22 PM
  • As of a couple of weeks ago the documentation said that only SQLite is supported. If that has changed before then then they should update the documentation.

    SQLite databases says "Universal Windows Platform (UWP) supports and recommends SQLite for local storage across all Windows 10 device families.".

    Entity framework Core with SQLite for C# apps says "Currently EF only supports SQLite on UWP.".

    SQLite Database Provider - EF Core lists only SQLite (3.7 onwards) for Supported Database Engines.

    You are vague about what the presentation by Stefan Wick and Ginny Caughey. Can you provide relevant details and/or a link to something? Note that as far as I am concerned it is not official if it only exists in a video. We need something in text that makes it official. You should provide a link to support what you say; many arguments erupt in groups when people say things without providing something authoritive.

    Also note that you can update all those articles. Microsoft wants us to help.



    Sam Hobbs
    SimpleSamples.Info


    • Edited by Simple Samples Friday, October 20, 2017 5:35 PM merging content from other reply
    Friday, October 20, 2017 5:06 PM
  • Here is the link:

    https://channel9.msdn.com/Events/Ignite/Microsoft-Ignite-Orlando-2017/BRK2069

    By the way, I figured out where the problem is but I have not yet resolved it. The solution requires a link to an SQLExpress database. I have that set up and can access the database from VS 2017 w/o a problem. But when I run my UWP project access defaults to an older version of LocalDB and not SQLExpress despite my connection string pointing to the SQLExpress. No idea, where the UWP project gets the LocalDb connection string from. I have tried that connection also and it did not work.

    Digging into the error codes I realized that UWP does not like the older LocalDb version.

    That might be the problem after all: db versions. Despite using SQLExpress 2017 the LocalDb ist still the older 2016 version. I have not figured out yet how to get the newer version to appear although it is supposedly installed.

    In short I have 2 problems:

    why does my UWP program default to LocalDb despite getting a SQLExpress connection string, and

    how do I get the newest version of LocalDb to show. 

    Friday, October 20, 2017 11:38 PM
  • I was able to find the problem with the UWP program defaulting to the old LocalDb.

    This is pulled from: ApplicationData.Current.LocalSettings.Values["sqlconnection"]

    I just assigned the SQLExpress connection string to it and now that is working.

    However, the database connection still does not open:

    Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.SqlClient.dll
    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)

    Saturday, October 21, 2017 3:40 PM
  • @hapzfl

    Sorry for the delay.

    I have reported the issue to the related team. They are investigating this.

    Thank you for your patience.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 26, 2017 3:12 AM
    Moderator
  • Great. I hope they will have a solution soon.
    Thursday, October 26, 2017 12:27 PM
  • I was able to find the problem with the UWP program defaulting to the old LocalDb.

    This is pulled from: ApplicationData.Current.LocalSettings.Values["sqlconnection"]

    I just assigned the SQLExpress connection string to it and now that is working.

    However, the database connection still does not open:

    Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.SqlClient.dll
    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)


    It seems that the "Data Source = LocalDB\SQLEXPRESS" is not supported in UWP, you should use IP address. E.g, Data Source=127.0.0.1\SQLEXPRESS
    • Edited by jerryaqw Monday, October 30, 2017 10:00 AM
    Monday, October 30, 2017 2:06 AM
  • Maybe you misunderstood my initial problem description. The program used to default to LocalDb despite my setting the proper SQLExpress string.

    I am NOT using LocalDB as my connection string. I am using "Data Source=pcname\SQLEXPRESS;..."

    That string is the same as the SQL Object Explorer database property shows as connection string.

    Monday, October 30, 2017 1:39 PM
  • If you look at the sample's code you'll see that it uses the connectionString only on first run to initialize the sqlconnection localSettings ( App.xaml.cs lines 63-72). This is why the comment when setting connectionString is to reinstall the app. Uninstalling will remove the store local data and then reinstall will again give the first run experience.

    After first run, you can update the stored sqlconnections from the app's settings pane.

    Tuesday, October 31, 2017 12:38 AM
  • If you look at the sample's code you'll see that it uses the connectionString only on first run to initialize the sqlconnection localSettings ( App.xaml.cs lines 63-72). This is why the comment when setting connectionString is to reinstall the app. Uninstalling will remove the store local data and then reinstall will again give the first run experience.

    After first run, you can update the stored sqlconnections from the app's settings pane.

    Sorry, but I am not sure I understand what you are trying to address. 

    My sample is by now using the supposedly proper "Data Source=pcname\SQLEXPRESS;..."connectionstring but strangely enough it still does not connect.

    Tuesday, October 31, 2017 5:14 PM
  • UWP applications have restrictions with access to network. Try to add Internet (Client & Server), Internet (Client) and Private Networks (Client & Server) capabilities in the project settings.
    Thursday, November 9, 2017 1:53 AM
  • UWP applications have restrictions with access to network. Try to add Internet (Client & Server), Internet (Client) and Private Networks (Client & Server) capabilities in the project settings.
    I was having this same issue and choosing those plus Enterprising Authentication in Package.appxmanifest resolved the issue.  Thanks!
    Thursday, February 1, 2018 1:42 AM
  • I have resolved a very similar issue after a few nights of troubleshooting.

    I allowed SQL server and SQL server browser through the windows firewall. (tutorial here)

    I then enabled SQL server browser (was disabled by default for some reason) in the services by opening services ->SQL Server Browser ->Startup Type set to Automatic. It was disabled. I then opened services again -> right click SQL server browser -> start. (tutorial here)

    My appplication now works! It says the connection is open when asking for the state with no errors (changed the program a little to a button / textbox to show it's connecting).

    It took a lot of research and looking around, and I am so glad there are other people making videos / posting on forums helping troubleshoot connection issues like this. I also changed some other settings, added the capabilities recommended above, and even uninstalled McAfee. (Uninstalling McAfee probably wasn't necessary)

    Thanks to all!




    Thursday, February 1, 2018 2:35 AM