I am trying to update an MVC project from NPoco 3 to NPoco 5.
I could no longer use:
using var db = new Database("DB");
so I changed it to:
using var db = new Database(ConfigurationManager.ConnectionStrings["DB"].ConnectionString, DatabaseType.SqlServer2012, SqlClientFactory.Instance);
and I even tried:
using var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
conn.Open();
using var db = new Database(conn);
But no matter what I try,
I just get
Value cannot be null
[Exception: No database type found for the type string specified: 'SqlServerDatabaseType'. Make sure the relevant assembly NPoco.SqlServer is referenced.]
NPoco.DynamicDatabaseType.MakeSqlServerType(String type) +194
NPoco.DatabaseType.Resolve(String typeName, String providerName) +298
NPoco.Database..ctor(DbConnection connection, DatabaseType dbType, Nullable`1 isolationLevel, Boolean enableAutoSelect) +111
How do I open a Database connection in version 5 of NPoco? It doesn't seem to work at all.
(I did notice that I am building to .NET Framework 4.6.1, which is also what NPoco 5 says it works on.)
Thanks for any help if anyone else has seen this.
In a change from Version 3 to Version 5, you must also now add the NuGet package NPoco.SqlServer.
Related
hi I'm new to Linux and mono. I am using Mono 3.6 and Debian 7.6
I keep getting object reference not set to an instance of an object. I use the same code that I compile on windows with VS 2013 and it works fine.
string connstring = string.Format
("Data Source={0},{1};Initial Catalog={2};User ID={3};Password={4};Application Name={5};Connect Timeout=120",
IP, Port, database, Username, Password, InstanceID);
settings = new ConnectionStringSettings("sqlServer",
connstring, "System.Data.SqlClient");
using (data = new SwitchDataDataContext(settings.ConnectionString)){
BlockList.Clear();
foreach (var item in data.BlockLists)
{// so this works
if (BlockList.ContainsKey(item.TN) == false)
BlockList.TryAdd(item.TN, item.TN);
}
// this is where it crashes
var custs = data.CustomerGateways.Where(p => p.isEnabled == true);
}
When I call the code it throws an exception.
Any idea what could be wrong?
works fine on Windows.
I wrote the exception to the screen. DbLinq.Data.Linq.Mapping.AttributedMetaType+c__Iterator0.MoveNext() [0x00000] in :0 at System.Collections.Generic.List System.Data.Linq.Mapping.MetaAssociation .AddEnumerable
Ok I figured it out. In the Linq's Map for all the tables you have joins. Those joins need to be Internal not Public. I've done this in the past when I have to serialize the data. Public for some reason causes like a looping of PK's.
Either way change the thing to internal in the Linq Map and it works.
I am trying to use a parametrized query to create an index on our Oracle server. I can create the index fine if I use string concatenation, so I believe its not an account or permissions issue. I get the error:
ORA-01036: illegal variable name/number
I can not find any error in the code, but I am sure I am missing something. I am using Oracle.DataAccess.dll version 4.112.3.0. The version the server reports is "Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production"
I have tried removing all the params, except one and get the same error. Any combination of 1 or more params causes the error. The error happens every time without fail. I have used watches to verify that the params are correctly getting set, and I have tried clearing the params before setting. No matter what I do so far, I still get the error. Here is the code:
using (OracleCommand mycom = new OracleCommand())
{
using (OracleConnection Connection = new OracleConnection(connectionString))
{
mycom.BindByName = true;
mycom.CommandText = "CREATE INDEX :indexname on :tablename (:colname)";
mycom.Parameters.Add("indexname", indexName);
mycom.Parameters.Add("tablename", tableName);
mycom.Parameters.Add("colname", colName);
mycom.Connection = Connection;
mycom.CommandType = CommandType.Text;
mycom.Connection.Open();
mycom.ExecuteNonQuery();
}
}
You cannot use bind variables in a DDL statement (like CREATE INDEX). Bind variables are only used in DML statements. You would need to build up the DDL statement in your C# code.
Is this a part of the installation process for your application? Otherwise, it would be exceedingly unusual to want to create an index from an application. Your application shouldn't be creating any database objects outside of the initial installation process.
I have a set of files (around 20MB each) that needs to be inserted into a table in mysql. The insert is done in a loop for all files (single threaded). This works usually fine, but from time to time I am getting the following exception: File '.table.MYD' not found (Errcode: 13) for one file in the middle of the set (the first 50 ran ok, next 2-3 will fail and then the following will run fine again). If I just re-run the queries for the failed files in mysql workbench (or re-run the failed ones), they are working fine. The table is just created, with no indexes - so problems like 'index failed', table fragmentation or any other problems should not be there.
Below is the complete stacktrace:
File '.dbtable.MYD' not found (Errcode: 13)
----------------------------------
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at Utils.SqlUtils.ExecMysql(String sql, String connection)
at Utils.MySqlExecQueue.DoExec(Object data)
----------------------------------
MySql.Data
where:
+ ExecMysql - looks like
using (MySqlConnection cnn = new MySqlConnection(connection))
{
cnn.Open();
using (MySqlCommand cmd = new MySqlCommand(sql, cnn))
{
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
+DoExec is a method that pics the files from a queue, creates the sql statement and calls ExecMysql above.
+the inserting code and mysql are on the same machine (Windows 2008, x64);
+there are no antiviruses or any other tool running on that machine that may lock the table file (as found on some blogs);
+the c# (.net 4) code is using mysql connector 6.5.4, the mysql version is 5.5;
I have implemented a dummy workaround like 'try-to-insert-while-13error-exception-is-thrown' but I have a strong feeling that this is not the correct solution.
Any ideea what is going on and how to fix this issue once and for all?
UPDATE - Clearly, the 'try-to-insert-while-13error-exception-is-thrown' fix is not a good ideea: I just got the same exception while running a SELECT on the table right after succesfully inserted data.
UPDATE 2 - checked the logs and I have noticed another wierd exception: Error on rename of '.\db\table.MYD' to '.\db\#sql2-4e4-1677.MYD' (Errcode: 17) ... things are getting better ...
do you have any anti-virus? If so make sure the mysql directory and its temp folder are excluded from AV and try again.
I have a Sqlite database that I include with my MonoTouch app. It has worked fine for me so far, but now I want to open it in read-only mode rather than read-write.
So I have changed the connection string to include 'Read Only=True', but when I call Open(), I get the following error:
Library used incorrectly (at Mono.Data.Sqlite3.Open)
If I dig into the exception it shows
_errorCode = Misuse
and that's about all the info it gives.
Here's the code:
var _conn = new SqliteConnection("Data Source=db/sampleDb;Read Only=True");
_conn.Open ();
You found a bug in Mono.Data.Sqlite.dll.
The Create flag is appended (by default) before the ReadOnly flag is parsed and set. The resulting flag is invalid and sqlite reports an error.
I will fix this for future releases (of Mono and MonoTouch...). If this blocks you then please open a bug report on http://bugzilla.xamarin.com and I'll attach a fixed assembly (with instructions to replace the existing one) to the bug report.
This worked for me (aspnet core):
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ReadOnly");
Have you tried?:
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ro");
Your code is correct, I just tried it (not using MonoTouch) and it worked for me.
Do you have the latest version of System.Data.SQLite.dll?
If yes, then maybe it's a problem related to MonoTouch.
My development machine is running Windows 7 Enterprise, 64-bit version. I am using Visual Studio 2010 Release Candidate. I am connecting to an Oracle 11g Enterprise server version 11.1.0.7.0. I had a difficult time locating Oracle client software that is made for 64-bit Windows systems and eventually landed here to download what I assume is the proper client connectivity software. I added a reference to "Oracle.DataAccess" which is version 2.111.6.0 (Runtime Version is v2.0.50727). I am targeting .NET CLR version 4.0 since all properties of my VS Solution are defaults and this is 2010 RC. I was then able to write a console application in C# that established connectivity, executed a SELECT statement, and properly returned data when the table in question does NOT contain a spatial column. My problem is that this no longer works when the table I query has a column of type SDO_GEOMETRY in it.
Below is the simple console application I am trying to run that reproduces the problem. When the code gets to the line with the "ExecuteReader" command, an exception is raised and the message is "Unsupported column datatype".
using System;
using System.Data;
using Oracle.DataAccess.Client;
namespace ConsoleTestOracle
{
class Program
{
static void Main(string[] args)
{
string oradb = string.Format("Data Source={0};User Id={1};Password={2};",
"hostname/servicename", "login", "password");
try
{
using (OracleConnection conn = new OracleConnection(oradb))
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from SDO_8307_2D_POINTS";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
}
}
catch (Exception e)
{
string error = e.Message;
}
}
}
}
The fact that this code works when used against a table that does not contain a spatial column of type SDO_GEOMETRY makes me think I have my windows 7 machine properly configured so I am surprised that I get this exception when the table contains different kinds of columns. I don't know if there is some configuration on my machine or the Oracle machine that needs to be done, or if the Oracle client software I have installed is wrong, or old and needs to be updated.
Here is the SQL I used to create the table, populate it with some rows containing points in the spatial column, etc. if you want to try to reproduce this exactly.
SQL Create Commands:
create table SDO_8307_2D_Points (ObjectID number(38) not null unique, TestID number, shape SDO_GEOMETRY);
Insert into SDO_8307_2D_Points values (1, 1, SDO_GEOMETRY(2001, 8307, null, SDO_ELEM_INFO_ARRAY(1, 1, 1), SDO_ORDINATE_ARRAY(10.0, 10.0)));
Insert into SDO_8307_2D_Points values (2, 2, SDO_GEOMETRY(2001, 8307, null, SDO_ELEM_INFO_ARRAY(1, 1, 1), SDO_ORDINATE_ARRAY(10.0, 20.0)));
insert into user_sdo_geom_metadata values ('SDO_8307_2D_Points', 'SHAPE', SDO_DIM_ARRAY(SDO_DIM_ELEMENT('Lat', -180, 180, 0.05), SDO_DIM_ELEMENT('Long', -90, 90, 0.05)), 8307);
create index SDO_8307_2D_Point_indx on SDO_8307_2D_Points(shape) indextype is mdsys.spatial_index PARAMETERS ('sdo_indx_dims=2' );
Any advice or insights would be greatly appreciated. Thank you.
Here is a link to a post with a sample app using C# and ODP.net to access spatial types.
http://www.orafaq.com/forum/mv/msg/27794/296419/0/#msg_296419
There is also a sample here about using XML to select the spatial types:
http://forums.oracle.com/forums/thread.jspa?threadID=241076