SqlGeography.STGeomFromText throw exception when creating Polygon - sql-server

During creating Polygon it throws execution. I am using library Microsoft.SqlServer.Types latest version 160.
polyText = "POLYGON ((
45.3972179 8.8406638000000157,
45.4215054 8.9151509000000715,
45.4001544 8.9361126999999669,
45.4016369 8.9607184999999845,
45.3851877 8.9621395000000348,
45.3853039 8.948319999999967,
45.3747296 8.9535720999999739,
45.3858019 8.9360727000000679,
45.3579525 8.8890794000000142,
45.3414371 8.90664240000001,
45.3452409 8.91328980000003,
45.3273192 8.92622259999996,
45.3185438 8.9208002999999962,
45.3405949 8.8954118000000335,
45.3471543 8.866777299999967,
45.3587372 8.8690788999999768,
45.3675493 8.8504374999999982,
45.3972179 8.8406638000000157,
45.3972179 8.8406638000000157,
45.3972179 8.8406638000000157
))
"
SqlGeography poly = SqlGeography.STGeomFromText(new SqlChars(polyText), 4326);
Exception statk
SQL Server Spatial library could not be loaded. Error code: 126 (HResult: 0x80131524).
Microsoft.SqlServer.Types
System.IO.FileNotFoundException: SQL Server Spatial library could not be loaded. Error code: 126 (HResult: 0x80131524).
at Microsoft.SqlServer.Types.GLNativeMethods.ThowIfGLNativeLibraryNotLoaded()
at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIsValid(GeoData& g, Double eccentricity, Boolean forceKatmai)
at Microsoft.SqlServer.Types.SqlGeography.IsValidExpensive(Boolean forceKatmai)
at Microsoft.SqlServer.Types.SqlGeography..ctor(GeoData g, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.STGeomFromText(SqlChars geometryTaggedText, Int32 srid)
at webNet.Area.Default.DrawShapesFromSql(String polyText, String areaName) in C:\Project\webNet\Area\Default.aspx.cs:line 474
at webNet.Area.Default.LoadForm() in C:\Project\webNet\Area\Default.aspx.cs:line 93
Created SqlGeography.Point it works fine without problem, only creating reading inserting polygon due it throws error.

I managed to resolve this exception by downgrading Microsoft.SqlServer.Types to version 14

Related

System.AccessViolationException when querying Access Database on Offices x64

I get the following error :
An unhandled exception of type 'System.AccessViolationException' occurred. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Here is the code where the unhandled exception is thrown (ExecuteScalar) :
Public Shared Function RequeteScalarInteger(ByVal pConnectionBDD As OleDb.OleDbConnection, ByVal pStrSql As String) As Integer
Dim retour As Object = -1
Try
Dim command As OleDbCommand = New OleDbCommand(pStrSql, pConnectionBDD)
retour = command.ExecuteScalar() 'here is the unhandled error
If IsNumeric(retour) Then
retour = CInt(retour)
ElseIf retour Is DBNull.Value Then
retour = -1
ElseIf retour = Nothing Then
retour = 0
Else
retour = -1
End If
command = Nothing
Catch ex As Exception
retour = -1
Debug.Write("RequeteScalarInteger:" & pStrSql)
My.Application.Log.WriteEntry(Now & " - " & ex.Message & vbCrLf & ex.StackTrace & vbCrLf & pStrSql)
End Try
Return CInt(retour)
End Function
Here is the connection string :
"Provider=Microsoft.ACE.OLEDB.12.0;Data source=" & pPathBDD
And here is the Stack trace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteScalar()
at QuizzDll.Bdd.RequeteScalarInteger(OleDbConnection pConnectionBDD, String pStrSql) in C:\QuizzBox_Solution_Git\QuizzDll\modules\Bdd.vb:line 273
at QuizzDll.Bdd.RequeteScalarInteger(String pStrSql) in C:\QuizzBox_Solution_Git\QuizzDll\modules\Bdd.vb:line 259
at QuizzDll.Bdd.GetClePrimaire(String pStrNomTable) in C:\QuizzBox_Solution_Git\QuizzDll\modules\Bdd.vb:line 518
at QuizzDll.ListePersonneSessionActive.Adapter_RowUpdated(Object sender, OleDbRowUpdatedEventArgs e) in C:\QuizzBox_Solution_Git\QuizzDll\Session\ListePersonneSessionActive.vb:line 1088
at System.Data.OleDb.OleDbDataAdapter.OnRowUpdated(RowUpdatedEventArgs value)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at QuizzDll.dsListePersonneFiltreTableAdapters.tPersonneTableAdapter.Update(tPersonneDataTable dataTable) in C:\QuizzBox_Solution_Git\QuizzDll\Datasets\dsListePersonneFiltre.Designer.vb:line 3209
at QuizzDll.ListePersonneSessionActive.UpdateInBDD() in C:\QuizzBox_Solution_Git\QuizzDll\Session\ListePersonneSessionActive.vb:line 1070
at QuizzDll.ListePersonneSessionActive.ListePersonneSessionActive_ListChanged(Object sender, ListChangedEventArgs e) in C:\QuizzBox_Solution_Git\QuizzDll\Session\ListePersonneSessionActive.vb:line 77
at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
at QuizzDll.ListePersonneSessionActive.InsertItem(Int32 index, PersonneSessionActive item) in C:\QuizzBox_Solution_Git\QuizzDll\Session\ListePersonneSessionActive.vb:line 86
at System.ComponentModel.BindingList`1.AddNewCore()
at System.ComponentModel.BindingList`1.System.ComponentModel.IBindingList.AddNew()
at System.Windows.Forms.CurrencyManager.AddNew()
at Telerik.WinControls.Data.RadListSource`1.AddNew()
at Telerik.WinControls.UI.GridViewNewRowInfo.EndAddNewRow()
at Telerik.WinControls.UI.GridViewNewRowInfo.OnEndEdit()
at Telerik.WinControls.UI.GridViewEditManager.FinishEditingOperation()
at Telerik.WinControls.UI.GridViewEditManager.EndEdit()
at Telerik.WinControls.UI.GridNewRowBehavior.ProcessEnterKey(KeyEventArgs keys)
at Telerik.WinControls.UI.BaseGridBehavior.ProcessKey(KeyEventArgs keys)
at Telerik.WinControls.UI.BaseGridEditor.OnKeyDown(KeyEventArgs keyEventArgs)
at System.Windows.Forms.KeyEventHandler.Invoke(Object sender, KeyEventArgs e)
at Telerik.WinControls.RadItem.OnKeyDown(KeyEventArgs e)
at Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyDown(Object sender, KeyEventArgs e)
at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at QB_Utilisateur.My.MyApplication.Main(String[] Args) in :line 81 ```
I have this problem only on x64 offices (in all versions 2010, 2013, 2016, 2019 and 365). Everythings works fine on x86 Offices.
My project is well set (x64 platform target) and uses framework 4.8.
I've tried to install AccessDatabaseEngine x64 (2010 and 2016) but i still have the issue.
I've tried the following solutions :
Attempted to read or write protected memory. This is often an indication that other memory is corrupt
Attempted to read or write protected memory
...with no luck ...
in the event viewer i get the following :
Nom du module défaillant : ACECORE.DLL, version : 16.0.4654.1000, horodatage : 0x5a5f3614
Code d’exception : 0xc0000005
Décalage d’erreur : 0x0000000000067ffb
ID du processus défaillant : 0xe8
Heure de début de l’application défaillante : 0x01d65a8cfcdcdd12
Chemin d’accès de l’application défaillante : C:\Program Files\QuizzBox\QB_Utilisateur.exe
Chemin d’accès du module défaillant: C:\Program Files\Common Files\Microsoft Shared\OFFICE16\ACECORE.DLL
ID de rapport : 35a97517-1ba5-4c8f-89fc-7889842b375a
Nom complet du package défaillant :
ID de l’application relative au package défaillant :
XML de l’événement :
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Application Error" />
<EventID Qualifiers="0">1000</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>100</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2020-07-15T09:48:18.1625753Z" />
<EventRecordID>6015</EventRecordID>
<Correlation />
<Execution ProcessID="0" ThreadID="0" />
<Channel>Application</Channel>
<Computer>DESKTOP-FSPFO7H</Computer>
<Security />
</System>
<EventData>
<Data>QB_Utilisateur.exe</Data>
<Data>6.2.1.0</Data>
<Data>5ed6029f</Data>
<Data>ACECORE.DLL</Data>
<Data>16.0.4654.1000</Data>
<Data>5a5f3614</Data>
<Data>c0000005</Data>
<Data>0000000000067ffb</Data>
<Data>e8</Data>
<Data>01d65a8cfcdcdd12</Data>
<Data>C:\Program Files\QuizzBox\QB_Utilisateur.exe</Data>
<Data>C:\Program Files\Common Files\Microsoft Shared\OFFICE16\ACECORE.DLL</Data>
<Data>35a97517-1ba5-4c8f-89fc-7889842b375a</Data>
<Data>
</Data>
<Data>
</Data>
</EventData>
</Event>
I've been here and it's quite a nightmare. On some systems, you may have to use a newer provider, such as(note the 16):
"Provider=Microsoft.ACE.OLEDB.16.0;Data source=" & pPathBDD
Something else to try,
"Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" & pPathBDD

How to display specified table column for Error Number: 22001/8152 SQL Server String or binary data would be truncated?

I get Error Number: 22001/8152
SQL [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]String or binary data would be truncated.
that means
one of my columns in the source table is bigger than my destination columns.
unfortunately that messsage not display which column is it who , I work with much table columns structure it is about 161 column. I think checking one by one my parameter value and column size is not good deal.
is there fastest way to do that?
this is my inssert query look like
INSERT INTO "my_db"."dbo"."my_table" ("Indeks_Keterpaduan", "NA", "admin_pembiayaan", "adopt_b2", "aktivitas_id", "aktivitas_nama", "assessment", "catatan", "dba_", "dlokasi", "dukungan_kawasan", "ikk_id", "ikk_nama", "ikp_id", "ikp_nama", "isu_strategis_id", "isu_strategis_nama", "jaringan_jalan", "jenis_arahan", "jenis_kegiatan", "jenis_kontrakID", "jenis_kontrakNama", "jenis_kotrakKode", "jenis_sub_aktivitas", "kabkot", "kawasan_nama", "kecamatan_id", "kegiatan_id", "kegiatan_nama", "ket_lokasi", "keterangan", "kewenangan", "kode_ssp", "kode_sspn", "kpk", "kws_kode", "outcome_id", "outcome_nama", "output_id", "output_nama", "param_a", "param_b", "param_c", "param_d", "param_e", "param_total", "phln", "politik_anggaran", "prioritas", "program_id", "program_nama", "provinsi_id", "rc_DED", "rc_DEDalokasi", "rc_DEDsatuan", "rc_DEDvol", "rc_Dokling", "rc_Doklingalokasi", "rc_Doklingsatuan", "rc_Doklingvol", "rc_FS", "rc_FSalokasi", "rc_FSsatuan", "rc_FSvol", "rc_dokptanah", "rc_kesesuaian_rtrw", "rc_konstruksi", "rc_konstruksialokasi", "rc_konstruksisatuan", "rc_konstruksivol", "rc_lahan", "rc_lahanalokasi", "rc_lahansatuan", "rc_lahanvol", "rc_masterplan", "rc_pnp1", "rc_pnp2", "rc_proposalpnp", "rc_rdtr", "rc_rdtralokasi", "rc_rdtrsatuan", "rc_rdtrvol", "rc_rispam", "rc_rispamalokasi", "rc_rispamsatuan", "rc_rispamvol", "rc_rp2kpkp", "rc_rp2kpkpalokasi", "rc_rp2kpkpsatuan", "rc_rp2kpkpvol", "rc_rtbl", "rc_rtblalokasi", "rc_rtblsatuan", "rc_rtblvol", "rc_sddt", "rc_skbup", "rc_skbupalokasi", "rc_skbupsatuan", "rc_skbupvol", "rc_skma", "rc_skt", "rc_spb", "rc_spd", "rc_spp", "readines", "rmp", "rpm", "sa1thn_id", "sajp_id", "sastra_id", "sastra_uraian", "satuan_output", "sbsn", "score_admin_pembiayaan", "score_jaringan_jalan", "score_kpk", "score_politik_anggaran", "score_readines", "sinkronisasi", "status", "status_konreg", "status_rakor", "status_verifikasi", "sub_aktivitas", "subkawasan_nama", "suboutput_id", "suboutput_nama", "sumber_arahan", "sumber_dana", "sumber_data_lainnya", "sumber_input_data", "tahun_anggaran", "tapisan", "time_create", "time_update", "total_score", "unit_id", "unit_nama", "uraian_ssp", "uraian_sspn", "user_create", "user_update", "volume", "waa_", "wab_", "wac_", "wba_", "wbb_", "wbc_", "wca_", "wcb_", "wcc_", "wda_", "wdb_", "wdc_", "wps_kode", "wps_nama", "x", "y")values (value1,value2,...,value (n))
Unfortunately, prior to SQL Server 2019, there's no easy way to pinpoint the cause of error msg 8152 "String or Binary data would be truncated".
While not an ideal solution (but it could save your sanity!), what you could do is install a local, side-by-side preview instance of SQL Server 2019, and run your application against it just to get the exact cause of the error!
Ref: String or Binary data would be truncated: replacing the infamous error 8152

Flink Error - Key group is not in KeyGroupRange

I am running a Flink graph using RocksDB as my statebackend. For one of the join operators in my graph, I get the below exception. (the actual group #s vary of course from run to run).
java.lang.IllegalArgumentException: Key group 45 is not in
KeyGroupRange{startKeyGroup=0, endKeyGroup=42}.
My operator is not too is as follows
Source1 -----> Map1A ---> KeyBy--->\___ >
\----> Map1B ---> KeyBy--->-----> Join1AB ---->
\____>
Source2 ----->------------KeyBy---> -----------------> Join2,1AB ---->
The error is thrown for in the Join2,1AB operator which joins (a) the result of Join1AB with the (keyed) source2.
Any ideas what could be causing this? I have the full stacktrace below, and I understand this is still very vague - but any pointers in the right direction is much appreciated.
Caused by: java.lang.IllegalArgumentException: Key group 45 is not in KeyGroupRange{startKeyGroup=0, endKeyGroup=42}.
at org.apache.flink.runtime.state.KeyGroupRangeOffsets.computeKeyGroupIndex(KeyGroupRangeOffsets.java:142)
at org.apache.flink.runtime.state.KeyGroupRangeOffsets.setKeyGroupOffset(KeyGroupRangeOffsets.java:104)
at org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend$RocksDBFullSnapshotOperation.writeKVStateData(RocksDBKeyedStateBackend.java:664)
at org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend$RocksDBFullSnapshotOperation.writeDBSnapshot(RocksDBKeyedStateBackend.java:521)
at org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend$3.performOperation(RocksDBKeyedStateBackend.java:417)
at org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend$3.performOperation(RocksDBKeyedStateBackend.java:399)
at org.apache.flink.runtime.io.async.AbstractAsyncIOCallable.call(AbstractAsyncIOCallable.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.flink.util.FutureUtil.runIfNotDoneAndGet(FutureUtil.java:40)
at org.apache.flink.streaming.runtime.tasks.StreamTask$AsyncCheckpointRunnable.run(StreamTask.java:897)
... 5 more
[CIRCULAR REFERENCE:java.lang.IllegalArgumentException: Key group 45 is not in KeyGroupRange{startKeyGroup=0, endKeyGroup=42}.]
EDIT: If I change my state backend to be file system (i.e. FsStateBackend), then I get the following stack trace. Something off with key group indexing.
java.lang.IllegalArgumentException: Key group index out of range of key group range [43, 86).
at org.apache.flink.runtime.state.heap.NestedMapsStateTable.setMapForKeyGroup(NestedMapsStateTable.java:104)
at org.apache.flink.runtime.state.heap.NestedMapsStateTable.putAndGetOld(NestedMapsStateTable.java:218)
at org.apache.flink.runtime.state.heap.NestedMapsStateTable.put(NestedMapsStateTable.java:207)
at org.apache.flink.runtime.state.heap.NestedMapsStateTable.put(NestedMapsStateTable.java:145)
at org.apache.flink.runtime.state.heap.HeapValueState.update(HeapValueState.java:72)
<snip user code stack trace>
org.apache.flink.streaming.api.operators.co.KeyedCoProcessOperator.processElement1(KeyedCoProcessOperator.java:77)
at org.apache.flink.streaming.runtime.io.StreamTwoInputProcessor.processInput(StreamTwoInputProcessor.java:242)
at org.apache.flink.streaming.runtime.tasks.TwoInputStreamTask.run(TwoInputStreamTask.java:91)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:263)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:702)
at java.lang.Thread.run(Thread.java:745)
The problem was my data objects (POJOs) had an mutable hashcode. Specifically, the hash code contained Enums. Example if I have a stream of Cars where the hashcode is composed of the car year and the car type (enum) as below.
Car {
private final CarType carType;
private final int carYear
public long hashCode() {
int result = 17;
result = 31 * result + carYear;
result = 31 * result + carType.hasCode(); <---- This is mutable!
}
}
The enum's hashCode is essentially Object.hashCode() (which is memory address dependent). Subsequently, the hashCode on one machine (or process) will not be the same as on another machine (or process). This also explains why I only ran into this problem when running in a distributed environment as opposed to running locally.
To resolve this, I changed my hashCode() to be immutable. Doing String.hashCode() is poor performance, so I may need to optimize that. But the below definition of Car will fix the problem.
Car {
private final CarType carType;
private final int carYear
public long hashCode() {
int result = 17;
result = 31 * result + carYear;
result = 31 * result + carType.name().hasCode(); <---- This is IMMUTABLE!
}
}

Loading data into R with rsqlserver package

I've just installed rsqlserver like so (no errors)
install_github('rsqlserver', 'agstudy',args = '--no-multiarch')
And created a connection to my database:
> library(rClr)
> library(rsqlserver)
Warning message:
multiple methods tables found for ‘dbCallProc’
> drv <- dbDriver("SqlServer")
> conn <- dbConnect(drv, url = "Server=MyServer;Database=MyDB;Trusted_Connection=True;")
>
Now when I try to get data using dbGetQuery, I get this error:
> df <- dbGetQuery(conn, "select top 100 * from public2013.dim_Date")
Error in clrCall(sqlDataHelper, "GetConnectionProperty", conn, prop) :
Type: System.MissingMethodException
Message: Method not found: 'System.Object System.Reflection.PropertyInfo.GetValue(System.Object)'.
Method: System.Object GetConnectionProperty(System.Data.SqlClient.SqlConnection, System.String)
Stack trace:
at rsqlserver.net.SqlDataHelper.GetConnectionProperty(SqlConnection _conn, String prop)
>
When I try to fetch results using dbSendQuery, I also get an error.
> res <- dbSendQuery(conn, "select top 100 * from public2013.dim_Date")
> df <- fetch(res, n = -1)
Error in clrCall(sqlDataHelper, "Fetch", stride) :
Type: System.InvalidCastException
Message: Object cannot be stored in an array of this type.
Method: Void InternalSetValue(Void*, System.Object)
Stack trace:
at System.Array.InternalSetValue(Void* target, Object value)
at System.Array.SetValue(Object value, Int32 index)
at rsqlserver.net.SqlDataHelper.Fetch(Int32 capacity) in c:\projects\R\rsqlserver\src\rsqlserver.net\src\SqlDataHelper.cs:line 116
Strangely, the file c:\projects\R\rsqlserver\src\rsqlserver.net\src\SqlDataHelper.cs doesn't actually exist on my computer.
Am I doing something wrong?
I am agstudy the creator of rsqlserver package. Sorry for the late but I finally I get some time to fix this bug. ( actually it was a not yet implemented feature). I demonstrate here how you can read/write data.frame with missing values in Sql server.
First I create a data.frame with missing values. It is important to distinguish the difference between numeric and character variables.
library(rsqlserver)
url = "Server=localhost;Database=TEST_RSQLSERVER;Trusted_Connection=True;"
conn <- dbConnect('SqlServer',url=url)
## create a table with some missing value
dat <- data.frame(txt=c('a',NA,'b',NA),
value =c(1L,NA,NA,2))
My input looks like this :
# txt value
# 1 a 1
# 2 <NA> NA
# 3 b NA
# 4 <NA> 2
I insert dat in my data base with the handy function dbWriteTable:
dbWriteTable(conn,name='T_TABLE_WITH_MISSINGS',
dat,row.names=FALSE,overwrite=TRUE)
Then I will read it using 2 methods:
dbSendQuery
res = dbSendQuery(conn,'SELECT *
FROM T_TABLE_WITH_MISSINGS')
fetch(res,n=-1)
dbDisconnect(conn)
txt value
1 a 1
2 <NA> NaN
3 b NaN
4 <NA> 2
dbReadTable:
rsqlserver is DBI compliant and implement many convenient functions to deal at least at possible with SQL.
conn <- dbConnect('SqlServer',url=url)
dbReadTable(conn,name='T_TABLE_WITH_MISSINGS')
dbDisconnect(conn)
txt value
1 a 1
2 <NA> NaN
3 b NaN
4 <NA> 2
(EDIT: I had missed something in your post (call to fetch). I can now reproduce the issue too.)
Short story is: do you have a NULL value in your database? this may be the cause.
Longer story, for a full repro:
I've used a sample DB reproducible by following the instructions at http://www.codeproject.com/Tips/326527/Create-a-Sample-SQL-Database-in-Less-Than-2-Minute
EDIT:
I can reproduce your issue with:
library(rClr)
library(rsqlserver)
drv <- dbDriver("SqlServer")
conn <- dbConnect(drv, url = "Server=Localhost\\somename;Database=Fabrics;Trusted_Connection=True;")
res <- dbSendQuery(conn, "SELECT TOP 100 * FROM [Fabrics].[dbo].[Client]")
str(res)
## Formal class 'SqlServerResult' [package "rsqlserver"] with 1 slots
..# Id:<externalptr>
> df <- fetch(res, n = -1)
Error in clrCall(sqlDataHelper, "Fetch", stride) :
Type: System.InvalidCastException
Message: Object cannot be stored in an array of this type.
Method: Void InternalSetValue(Void*, System.Object)
Stack trace:
at System.Array.InternalSetValue(Void* target, Object value)
at System.Array.SetValue(Object value, Int32 index)
at rsqlserver.net.SqlDataHelper.Fetch(Int32 capacity) in c:\projects\R\rsqlserver\src\rsqlserver.net\src\SqlDataHelper.cs:line 116
the following commands suggest things work as expected if using other commands.
> dbExistsTable(conn, name='Client')
Error in sqlServerExecScalar(conn, statement, ...) :
Message: There is already an open DataReader associated with this Command which must be closed first.
> dbClearResult(res)
[1] TRUE
> dbExistsTable(conn, name='Client')
[1] TRUE
> dbExistsTable(conn, name='SomeIncorrectColumn')
[1] FALSE
Note that I cannot reproduce the very odd one about MissingMethodException
df <- dbGetQuery(conn, "SELECT TOP 100 * FROM [Fabrics].[dbo].[Client]")
Error in clrCall(sqlDataHelper, "Fetch", stride) :
Type: System.InvalidCastException
Message: Object cannot be stored in an array of this type.
Method: Void InternalSetValue(Void*, System.Object)
Stack trace:
at System.Array.InternalSetValue(Void* target, Object value)
at System.Array.SetValue(Object value, Int32 index)
at rsqlserver.net.SqlDataHelper.Fetch(Int32 capacity) in c:\projects\R\rsqlserver\src\rsqlserver.net\src\SqlDataHelper.cs:line 116
Since the debug symbols seem present, I can debug it further through visual studio. It bombs in SqlDataHelper.Fetch at
_resultSet[_cnames[i]].SetValue(_reader.GetValue(i), cnt);
and the variable watch gives me:
i 11 int
_cnames[i] "Street2" string
_reader.GetValue(i) {} object {System.DBNull}
_reader.GetValue(i-1) "806 West Sir Francis Drake St" object {string}
_reader.GetValue(i+1) "Spokane" object {string}
The entry for Street2 is indeed a NULL:
ClientId FirstName MiddleName LastName Gender DateOfBirth CreditRating XCode OccupationId TelephoneNumber Street1 Street2 City ZipCode Longitude Latitude Notes
1 Nicholas Pat Kane M 1975-10-07 00:00:00.000 3 ZU8 5ML 4 (279) 459 - 2707 2870 North Cherry Blvd. NULL Carlsbad 64906 32.7608137325835 117.112738329071
For information, sessionInfo() output includes:
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
other attached packages:
[1] rsqlserver_1.0 rClr_0.5-2
loaded via a namespace (and not attached):
[1] DBI_0.2-7 tools_3.0.2
Hope this helps.

Why does ST_Union throw a "TopologyException: side location conflict"?

I'd like to understand the meaning of this error:
Error: ERROR: GEOSUnaryUnion: TopologyException: side location conflict at 509222.06405540626 166742.77073020922
SQLState: XX000
ErrorCode: 0
Given from the following query:
select ST_union(z.geom) from zaz z
Postgis version:
POSTGIS="2.1.0 r11822"
GEOS="3.3.6-CAPI-1.7.6"
PROJ="Rel. 4.8.0, 6 March 2012"
GDAL="GDAL 1.9.2, released 2012/10/08"
LIBXML="2.9.0" RASTER
The problem can be reproduced with this query:
select ST_AsText(ST_Union(z.geom)) from (
select ST_MPolyFromText('MULTIPOLYGON(((513571.981531803 166341.349774259,513116.037800698 166090.997380913,513119.013934713 166083.021341753,513122.34720481 166072.188213938,513124.013839858 166065.997855187,513126.037610988 166046.950597491,513126.037610988 166023.974842894,513117.942526467 165913.024566813,513116.990163582 165897.905806017,513104.966582162 165803.502835059,513104.60944608 165716.718767181,513124.013839858 164966.018723224,513054.967530709 164991.018248951,513040.682087437 164995.065791211,512771.639572476 165072.207184881,512658.070298462 165089.230671447,512620.332919151 165094.825803396,512222.007142577 165144.705809488,512088.319202621 165158.396025957,511825.467046411 165185.300277453,511437.260125488 165216.25207121,511039.767666438 165238.394508282,510637.275302243 165245.299139197,510278.115449307 165247.084819606,509844.671291355 165243.275368066,509480.630578634 165236.01360107,509195.516939992 165227.918516549,508870.642150909 167051.217259529,509104.804375213 166841.340288788,509222.064055406 166742.770730209,509415.631811745 166631.106181965,509727.887792604 166450.871506013,509849.6711965 166401.824817445,509922.407911828 166380.753788619,509986.811451913 166352.659083516,510105.975857876 166299.445807327,510225.259309199 166266.232151719,510464.302393288 166229.209044572,510544.777057055 166213.495056973,510668.227095999 166170.876817877,510762.034840154 166140.282160202,510828.938332812 166126.949079815,510890.365738883 166118.139723131,510959.05491195 166107.782776758,511018.33950153 166100.16387368,511066.076691131 166092.42592524,511097.742757051 166089.211700504,511281.786884542 166098.021057189,511590.471504583 166137.90125299,511730.825984733 166143.853521021,511766.896728995 166143.972566381,511806.419788715 166145.520156069,511905.108392654 166136.353663303,512001.535134742 166108.735139643,512202.95988488 166038.379331527,512434.145975169 165984.332737814,512507.120781218 165968.618750214,512581.643176955 165965.642616199,512654.379892283 166077.307164444,512784.496471421 166043.855418115,512787.948786879 166078.973799492,512787.948786879 166078.973799492,512767.830120937 166133.377529288,512774.020479688 166276.23196201,512799.020005415 166301.350533097,512836.400248644 166276.946234174,512874.018582594 166305.040939276,512838.066883692 166334.564188705,512845.090559968 166427.895751417,512806.996044575 166460.990361664,512846.757195016 166499.561058499,512858.899821797 166718.723567368,512820.329124962 166737.770825064,512833.900296071 166747.532544633,512821.043397126 166755.984765236,512877.708988772 166768.365482739,512893.899157814 166775.627249735,512930.68417424 166780.270018799,512977.469000957 166786.103241468,513181.393703668 166834.554703233,513269.011089071 166852.054371242,513314.605462182 166864.077952663,513568.886352428 166930.624309239,513908.760856946 167004.313387452,513964.593131069 167015.265560627,514336.967019032 167086.454686267,514356.252367449 167090.264137806,514374.10917154 167095.621179034,514433.274715759 166842.649787754,514423.036814747 166834.554703233,514403.037194166 166819.197851716,514302.443864457 166749.675361124,513950.664823878 166560.750373849,513571.981531803 166341.349774259)))') as geom
union
select ST_MPolyFromText('MULTIPOLYGON(((509658.841483455 166823.126348616,509700.031178223 166767.055983772,509737.292376092 166816.816944504,509780.982023433 166778.008156947,509821.338400677 166825.269165106,509862.051914003 166803.960045559,509727.887792604 166450.871506013,509415.631811745 166631.106181965,509480.987714716 166813.959855849,509442.417017881 166923.362542242,509390.751331379 167281.570032294,509425.988758117 167342.997438364,509448.012149829 167345.97357238,509478.963943585 167352.04488577,509503.963469312 167355.021019785,509530.986766168 167357.9971538,509555.986291895 167357.9971538,509583.961951636 167358.949516685,509588.009493897 167357.9971538,509603.009209333 167068.955018259,509651.579716458 167025.622507,509658.841483455 166823.126348616)),((509222.064055406 166742.770730209,509288.967548065 167023.955871951,509248.373080099 167078.002465664,509288.967548065 167023.955871951,509222.064055406 166742.770730209)))') as geom
) z
I'd also like to know if there is a way to "fix" one of the geometries to avoid
the error.
Strangely, if I create a table with a union of the two above selects, and then run an ST_Union, then it doesn't fail.
ST_MakeValid solves the problem.
The result can be passed to ST_Union:
ST_Union(st_makeValid(t.geom))
For the explanation, it could not be better than this one: PostGIS: Tips for power users.

Resources