Xamarin SqlServer cant get a connection

1

Im building with the Entity Framework on xamarin a app where i compare some data. But when im starting my "fetchdata" function i recive the Error:

System.Data.SqlClient.SqlException (0x80131904): Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35)Snix_Connect (provider: SNI_PN7, error: 35 - SNI_ERROR_35) 

And now where my hole setup is ready to go i see many posts about xamarin / android & that it is not possible to get a connection to a SqlServer. But time got by and so i hope that it is possible.

Is there any way to fetch Data from a sqlServer with .net core on xamarin?

android
.net
sql-server
xamarin
core
asked on Stack Overflow Aug 29, 2018 by Xami

3 Answers

1

This is the string I put into SQL_Class folder with Sql_Common.cs
Fill up the brace brackets with actual parameters (removing the brace brakets too).

public static string SQL_connection_string = @"data source={server_address};initial catalog={database_name};user id={user_id};password={password};Connect Timeout={seconds}";

Then I access whenever I need it from any xamarin code just like we use in our asp.net c#
This works for me on my app without any issues.

using (SqlConnection Sql_Connection = new SqlConnection(Sql_Common.saralEHR_connection_string))

But as @Jason mentioned in his first reply, I too would get once again check the security part. I fexperienced before publishing Package to Google Play, they encrypt the App files with Hash Key Code and then only it gets upload to server

answered on Stack Overflow Aug 30, 2018 by Yeshwant Mudholkar
0

Yes it is possible (HuurrAYY!): Im new in .net core, c# and so on and for me it was a hell of a work to get it working.. So here for the other noobs who are seeking for Help:

GuideĀ“s i used: Building Android Apps with Entity Framework https://medium.com/@yostane/data-persistence-in-xamarin-using-entity-framework-core-e3a58bdee9d1 https://blog.xamarin.com/building-android-apps-entity-framework/

Scaffolding https://cmatskas.com/scaffolding-dbcontext-and-models-with-entityframework-core-2-0-and-the-cli/

How i did it:

  1. Build your normal Xamarin app.
  2. create new .net solution like in the tutorials (DONT WRITE YOUR Entity Framework CLASSES)
  3. create a third solution what has to be a .net core console application
  4. Scaffold your DB in your CONSOLE application move all created classes & folders in your "xamarin .net" solution & change the namespaces
  5. Ready to Go!

Side Node: NuGets you need in every solution:

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.SqlServer

[EDIT: NuGets you need in every solution]

answered on Stack Overflow Aug 29, 2018 by Xami • edited Sep 4, 2018 by Xami
0

I am doing this way (working snippet):

string connectionString = @"data source={server};initial catalog={database};user id={user};password={password};Connect Timeout=10";
        string databaseTable = "{table name}";
        string selectQuery = String.Format("SELECT count(*) as Orders FROM {0}", databaseTable);
        try
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                //open connection
                connection.Open();

                SqlCommand command = new SqlCommand(selectQuery, connection);

                command.Connection = connection;
                command.CommandText = selectQuery;
                var result = command.ExecuteScalar().ToString();
                //check if there is result
                if(result != null)
                {
                    OrdersLabel.Text = result;
                }
            }
        }
        catch (Exception ex)
        {
            OrdersLabel.Text = ex.Message;
        }

It is working fine, but API call more elegant. I hope it helps.

answered on Stack Overflow Oct 22, 2019 by Zoltan

User contributions licensed under CC BY-SA 3.0