Bug 30609 - Issues with Connection to SQL Server
Summary: Issues with Connection to SQL Server
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.1
Hardware: PC Windows
: High normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2015-05-29 18:01 UTC by Anubhav Ranjan
Modified: 2015-06-10 03:09 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Sample Project (1.82 MB, application/octet-stream)
2015-05-29 18:01 UTC, Anubhav Ranjan
this problem is the lector() (126.86 KB, image/png)
2015-06-02 19:33 UTC, oescrich
image to string (519.50 KB, image/png)
2015-06-03 14:56 UTC, oescrich
project example (1.67 MB, application/octet-stream)
2015-06-04 02:35 UTC, oescrich
problem explain (272.18 KB, image/png)
2015-06-04 14:59 UTC, oescrich
project sample (1.67 MB, application/octet-stream)
2015-06-04 15:00 UTC, oescrich

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Anubhav Ranjan 2015-05-29 18:01:48 UTC
Created attachment 11396 [details]
Sample Project

Our customer is facing issues with using SQLServer connection in Android

I need help, I've created an app that makes a connection to SQL Server, when is debug mode I have no problem but when is in release mode shows the following error: "Item has already been added. Key in dictionary: '1252' Key being added: '1252'"
I noticed that the problem is when I try to read the info that comes from the server in the next line: if(reader.read()){
and the reader is a SqlDataReader type
Comment 2 Jonathan Pryor 2015-06-02 17:45:08 UTC
What is the full stack trace when the "Item has already been added" is thrown?

I'm not able to reproduce the error.
Comment 3 oescrich 2015-06-02 19:33:08 UTC
Created attachment 11444 [details]
this problem is the lector()

sqlserver makes the connection.

 but the return of information to the cursor is broken at that point in reléase mode
Comment 4 Jonathan Pryor 2015-06-03 12:15:47 UTC
I'm not asking for where the exception was caught.

I'm asking for the value of `ex.ToString()`. Note: .ToString(), NOT .Message, as .Messages doesn't have the stack trace for where the exception was thrown from.
Comment 5 oescrich 2015-06-03 14:56:50 UTC
Created attachment 11451 [details]
image to string

this is message that we get from tostring()
Comment 6 Jonathan Pryor 2015-06-03 15:44:38 UTC
@escrich: For future reference, `Console.WriteLine(ex.ToString())` then copying the Application Output window would be easier...
Comment 7 Jonathan Pryor 2015-06-03 15:51:18 UTC
@Eno: Looks like a refernecesource migration issue? As per Attachment #11451 [details], the exception is coming from Encoding.GetEncoding(), *probably* from here:


However, this doesn't make sense to me: Encoding.GetEncoding() doesn't loop over anything, and uses Encoding.encodings as a static cache, so the only idea that comes to mind for a failure is akin to this:


Best I can figure, `result` is null, making line 528 akin to:

    encodings.Add(1252, null);

which would cause the cache lookup on line 432 to fail (value is null) on the second invocation.
Comment 8 Jonathan Pryor 2015-06-03 16:02:28 UTC
@oescrich: Your project does not specify the West internationalization support assemblies:


Specifically, "prueba de conexión.csproj" contains:

    <MandroidI18n />

which means "don't do anything special regarding internationalization support."

Please change that to:


then rebuild your project and see if that fixes it.
Comment 9 oescrich 2015-06-03 18:32:17 UTC
the problem remains.
I used the west.

we are in El Salvador, Latin America.
Comment 10 oescrich 2015-06-04 02:35:57 UTC
Created attachment 11459 [details]
project example

I made the change, but the problem persists.

I do not understand how a few lines, you can not help me with the error.

I have reduced the application to a minimum.

 in debug mode works perfectly in release mode is a problem
Comment 11 Atsushi Eno 2015-06-04 13:21:45 UTC
Could you tell us how to reproduce the issue?

Also, I cannot reproduce the issue.
Should tapping the button show me the error message toast? Tapping twice?
I tried that, but only some non-English message toast showed up, which I guess is like "not connected" (because there is no connected SQL Server on my machine).
Comment 12 oescrich 2015-06-04 14:59:28 UTC
Created attachment 11465 [details]
problem explain

sending back the project.
the server ip is published
image explains in detail the problem
Comment 13 oescrich 2015-06-04 15:00:26 UTC
Created attachment 11466 [details]
project sample
Comment 14 Atsushi Eno 2015-06-05 05:42:08 UTC
Thanks for the screenshot. Yes, that "lectura correcta blahblah" is exactly what I saw for the first tap (so, I assume I am connected to your globally available server). The second tap was "conexion cerrada". I don't see that long exception message toast. And that's from Release mode.

I also tried setting the emulator's language to Portugese (Brazil) but the same results. I also tried adding explicit invocations for "Encoding.GetEncoding(1252);" within MainActivity.OnCreate(), but still not reproducible. It is not likely due to the language difference.

At this state the only idea I have is that (from jonp's comment #7) we had some thread blocking problem that lock didn't work properly but got fixed later versions I have. There is also chance that the commented code in encoding.cs may have locking issue too (but it is from Microsoft's referencesource, not part of our changes).

I will ask our QA team if they can reproduce it.

So far it needs to be changed to REOPENED, nothing is NEEDINFO.
Comment 15 oescrich 2015-06-05 14:59:15 UTC
I've solved the problem
Comment 16 Atsushi Eno 2015-06-05 15:55:46 UTC
(marking as NOT_REPRODUCIBLE as per comment #14 and #15.)
Comment 17 sun wells 2015-06-10 03:09:02 UTC
@ oescrich
How did u solve this issue, we are also facing same.
Please post the steps to resolve. Thanks in advance