SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
Specified Method Not Supported? [ reply ]
By: Joe Bagodonuts on 2008-01-10 20:22
[forum:1003008]
Hey, people -
I'm using the 2.0 Beta version of npgsql in a C#.Net app. I'm able to load the reference and see it in the Object Browser (even though I was unable to add it to the GAC -- "Failure adding assembly to the cache: Unknown Error" -- but that's another thread). I successfully connect to my test database, but when I try to list the tables using NpgsqlConnection.getSchema(collection) I get the Method Not Supported exception. getSchema() works fine with NO args, but I'm not getting what I want from that. Has anyone seen this and, if so, can you tell me a way to get past it? My thanks in advance...

Broken Connections [ reply ]
By: Andreas Schönebeck on 2008-01-09 10:38
[forum:1002997]
Hello from Berlin!

I'm running into trouble calling Thread.Abort() on a thread that is doing a NpgqslCommand.ExecuteReader(). The command and connection is created in the thread itself. Also there is only one Connection open at a time, because the main thread is waiting for completion using Thread.Join().

To illustrate the problem I've written a test to create 10 threads, which are aborted after a short random time (100-1000 ms) and a final thread, which is never aborted and should run cleanly to the end.

As you can see by the test's output there are various exceptions generated by the aborted threads and only sometimes the ThreadAbortException gets cleanly caught.

Which is weirdest is, that after the 10'th aborted thread catches a clean ThreadAbortException ("[9] Thread aborted.") the final thread, which should run till the end and read ~50000 records does throw an exception in ExecuteReader()!?!

In application context (user pressing "refresh" very quickly, high server load) the last database read will sometimes not return any results.

What can I do to improve stability? I hope, the test case code is giving an idea of my problem and someone has a quick and proper fix.

Maybe I found a bug in Npgsql and ThreadAbortExceptions are not handled properly and connections end up in corrupted state, but are reused by pooling?

Thanks for looking into this,
Andreas Schönebeck




// Output
[Main] Starting Thread [0].
[Main] Aborting Thread [0].
[Main] Waiting for Thread [0] to finish.
[0] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.

[Main] Starting Thread [1].
[Main] Aborting Thread [1].
[Main] Waiting for Thread [1] to finish.
[1] Unhandled exception caught (System.NotSupportedException): Backend sent unrecognized response type:

[Main] Starting Thread [2].
[Main] Aborting Thread [2].
[Main] Waiting for Thread [2] to finish.
[2] Unhandled exception caught (System.NotSupportedException): Backend sent unrecognized response type:

[Main] Starting Thread [3].
[Main] Aborting Thread [3].
[3] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.
[Main] Waiting for Thread [3] to finish.

[Main] Starting Thread [4].
[Main] Aborting Thread [4].
[4] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.
[Main] Waiting for Thread [4] to finish.

[Main] Starting Thread [5].
[Main] Aborting Thread [5].
[5] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.
[Main] Waiting for Thread [5] to finish.

[Main] Starting Thread [6].
[Main] Aborting Thread [6].
[6] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.
[Main] Waiting for Thread [6] to finish.

[Main] Starting Thread [7].
[Main] Aborting Thread [7].
[7] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.
[Main] Waiting for Thread [7] to finish.

[Main] Starting Thread [8].
[Main] Aborting Thread [8].
[8] Unhandled exception caught (System.NotSupportedException): Dieser Stream unterstützt keine Suchvorgänge.
[Main] Waiting for Thread [8] to finish.

[Main] Starting Thread [9].
[Main] Aborting Thread [9].
[Main] Waiting for Thread [9] to finish.
[9] Thread aborted.

[Main] Starting Thread [10].
[10] Unhandled exception caught (System.NotSupportedException): Dieser Streamunterstützt keine Suchvorgänge.
[Main] Waiting for Thread [10] to finish.
Press any key to continue . . .




// Source...
sing System;
using System.Threading;
using Npgsql;


class Program
{
public static void Main(string[] args)
{
RunTestAbort(0);
RunTestAbort(1);
RunTestAbort(2);

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}

public static void RunTestAbort(int id)
{
Thread dbthread = new Thread(AbortThreadFunc);
Console.WriteLine("[Main] Starting Thread [{0}].", id);
dbthread.Start(id);

Thread.Sleep(150);
Console.WriteLine("[Main] Aborting Thread [{0}].", id);
dbthread.Abort();

Console.WriteLine("[Main] Waiting for Thread [{0}] to finish.", id);
dbthread.Join();
}

public static void AbortThreadFunc(object parameter)
{
int id = (int)parameter;
NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder();
csb.Host = "localhost";
csb.Database = "gps";
csb.UserName = "postgres";
csb.Password = "postgres";
try {
using(NpgsqlConnection con = new NpgsqlConnection(csb.ConnectionString)) {
con.Open();
using(NpgsqlCommand cmd = con.CreateCommand()) {
cmd.CommandText = "SELECT * FROM original";
using(NpgsqlDataReader sdr = cmd.ExecuteReader()) {
int recordcount = 0;
while (sdr.Read()) {
recordcount++;
}
Console.WriteLine("[{0}] Successfully read {1} records.", id, recordcount);
}
}
}
} catch (ThreadAbortException ex) {
Console.WriteLine("[{0}] Thread aborted.", id, ex.StackTrace);
} catch (Exception ex) {
Console.WriteLine("[{0}] Unhandled exception caught ({1}): {2}", id, ex.GetType().ToString(), ex.Message);
}
}
}

Unplugging network causes null reference ex [ reply ]
By: Alex Simmens on 2008-01-03 17:59
[forum:1002973]
Hi, i've been experimenting with the NPGSQL2.0 beta 2 driver and i noticed a possible bug.

I have created 3 connections to a postgres db with the same connection string, and if i unplug my network cable and try an execute reader command such as SELECT * FROM queues WHERE queueno = 1; on one of the connections, after the command times out, i get an unhandled null reference exception in the NpgsqlConnectorPool.TimerElapsed Handler

on investigation, i found it to be caused by the queue object on this line being null:- (Queue.Count > 0)

i tried fixing it by adding a if (Queue != null) check before it and it seems to work, but as i don't understand how npgsql works and i don't know C# very well i may be being silly

hope it helps

alex

multiple threads with independent connections [ reply ]
By: Carl Strange on 2008-01-02 16:47
[forum:1002966]
I'm starting work on a personal project to gather data from various web sites. I'm relatively comfortable in C# and with SQL but this will be my first use of Npgsql and PostgreSQL.

My initial design has several web scrapers, running in separate threads, each with their own database connection. They simply post data to various tables so I shouldn't have interlock problems between threads. The main thread will periodically read the database to check on the worker's progress.

I understand a single database connection is not thread safe but are there any problems with independent connections on independent threads?

Regards,

Carl

I got 8 testcases failed. [ reply ]
By: Tao Wang on 2007-11-30 08:20
[forum:1002893]
Every time I run the testcase, I got 8 testcases failed. After I digged into, it looks like some testcases are wrong. The following is the test result:

------ Test started: Assembly: NpgsqlTests.dll ------

TestCase 'NpgsqlTests.CommandTests.DateTimeSupportTimezone'
failed:
String lengths are both 20. Strings differ at index 11.
Expected: "2002-02-02 16:00:23Z"
But was: "2002-02-02 09:00:23Z"
----------------------^
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\CommandTests.cs(941,0): at NpgsqlTests.CommandTests.DateTimeSupportTimezone()

TestCase 'NpgsqlTests.CommandTests.DateTimeSupportTimezone2'
failed:
Expected string length 20 but was 16. Strings differ at index 5.
Expected: "2002-02-02 16:00:23Z"
But was: "2002-2-2 9:00:23"
----------------^
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\CommandTests.cs(951,0): at NpgsqlTests.CommandTests.DateTimeSupportTimezone2()

TestCase 'NpgsqlTests.CommandTests.FunctionReturnVoid'
failed: Npgsql.NpgsqlException : ERROR: 42883: function test(integer) does not exist
F:\dev\Npgsql2\src\Npgsql\NpgsqlConnector.cs(353,0): at Npgsql.NpgsqlConnector.CheckErrors()
F:\dev\Npgsql2\src\Npgsql\NpgsqlConnector.cs(403,0): at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications()
F:\dev\Npgsql2\src\Npgsql\NpgsqlCommand.cs(1509,0): at Npgsql.NpgsqlCommand.ExecuteCommand()
F:\dev\Npgsql2\src\Npgsql\NpgsqlCommand.cs(463,0): at Npgsql.NpgsqlCommand.ExecuteNonQuery()
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\CommandTests.cs(651,0): at NpgsqlTests.CommandTests.FunctionReturnVoid()

TestCase 'NpgsqlTests.CommandTests.LastInsertedOidSupport'
failed: Npgsql.NpgsqlException : ERROR: 42703: column "oid" does not exist
F:\dev\Npgsql2\src\Npgsql\NpgsqlConnector.cs(353,0): at Npgsql.NpgsqlConnector.CheckErrors()
F:\dev\Npgsql2\src\Npgsql\NpgsqlConnector.cs(403,0): at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications()
F:\dev\Npgsql2\src\Npgsql\NpgsqlCommand.cs(1509,0): at Npgsql.NpgsqlCommand.ExecuteCommand()
F:\dev\Npgsql2\src\Npgsql\NpgsqlCommand.cs(706,0): at Npgsql.NpgsqlCommand.ExecuteScalar()
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\CommandTests.cs(1969,0): at NpgsqlTests.CommandTests.LastInsertedOidSupport()

TestCase 'NpgsqlTests.CommandTests.ListenNotifySupport' failed: System.InvalidOperationException was expected
TestCase 'NpgsqlTests.CommandTests.ParametersGetName'
failed:
Expected string length 10 but was 11. Strings differ at index 0.
Expected: "Parameter4"
But was: ":Parameter4"
-----------^
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\CommandTests.cs(73,0): at NpgsqlTests.CommandTests.ParametersGetName()

TestCase 'NpgsqlTests.DataAdapterTests.UpdateWithDataSet'
failed: System.InvalidOperationException : Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information
at System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow)
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(DataSet dataSet, String srcTable)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\DataAdapterTests.cs(212,0): at NpgsqlTests.DataAdapterTests.UpdateWithDataSet()

TestCase 'NpgsqlTests.DataReaderTests.SingleRowCommandBehaviorSupportFunctioncallPrepare'
failed:
Expected: 1
But was: 6
F:\dev\Npgsql2\testsuite\noninteractive\NUnit20\DataReaderTests.cs(530,0): at NpgsqlTests.DataReaderTests.SingleRowCommandBehaviorSupportFunctioncallPrepare()


162 passed, 8 failed, 0 skipped, took 20.45 seconds.

===================================

For NpgsqlTests.CommandTests.FunctionReturnVoid, there is no test() function in test db, and not in add_functions.sql (or testreturnvoid()?).

For NpgsqlTests.CommandTests.ParametersGetName, I think ":Parameter4" was correct, why expect "Parameter4", is it wrong?

Should we correct those testcases?

Cannot connect to database (Npgsql) [ reply ]
By: Chris Miles on 2007-12-11 15:12
[forum:1002939]
I have just installed Npgsql (stable), and I am having problems connecting to my database.

This is the code I am using:

NpgsqlConnection conn = new NpgsqlConnection("Server=192.168.0.50;Port=5432;User Id=cakeinaboxadmin;Password=cakeinaboxadmin;Database=cakeinabox;");
conn.Open();

Ip and port is valid - I can connect with pgadmin to the database without any problems.

An exception is thrown on the conn.Open() line:

"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

Full exception trace as follows:

http://pastebin.ca/812127

Thanks

Chris

Badly formed XML comments in npgsql.xml [ reply ]
By: Andrus Moor on 2007-11-11 20:08
[forum:1002815]
npgsql.xml contains a lot of messages like

<!-- Badly formed XML comment ignored for member "P:Npgsql.NpgsqlConnection.ConnectionString" -->

<!-- Badly formed XML comment ignored for member "M:Npgsql.NpgsqlConnection.GetSchema" -->

Login as Administrator [ reply ]
By: Vital Logic on 2007-12-08 07:02
[forum:1002929]
I want to create database from my application, using npgsql. However the connection string explicitly needs a database to be passed as paramenter. How can I solve this?

Similar is the case with creating users from the application.

Npgsql sunc notifications.How? [ reply ]
By: Dmitry Nizinkin on 2007-10-29 08:52
[forum:1002787]
Hi, I have Win xp sp2,Postgresql 8.2.0,npgsql 1.0 data provider.
I need recieve notify from Postgresql server when row add in table on server.I write trigger on insert.In body this trigger write: notify MyApp.
In my application do:
npgsqlconnection+=new EventHandler(func);
It's work, but async. My app recieve message when i send next command on server.How my application can recieve message immediately.Pls help me.

search for string with back slash [ reply ]
By: Sean Zeng on 2007-12-03 18:05
[forum:1002902]
Hi,

I met a weird problem when save a string with back slash then search for it.

1. I wrote two PG stored procedures, one to insert a string, one to retrieve it.

a. FUNCTION proc_add_value(i_value text) as:
INSERT INTO TEST_DATA (NAME) VALUES(I_VALUE);

b. FUNCTION proc_find_value(i_value text) as:
FOR O_NAME IN SELECT NAME FROM TEST_DATA WHERE UPPER(NAME) LIKE UPPER(I_VALUE) || '%'
LOOP
RETURN NEXT O_NAME;
END LOOP;

2. In C#, call the stored procedures through npgsql:

a. call proc_add_value with string parameter of @"HKLM\Software\test"
I can see the record is added correctly in pgadmin.

b. call proc_find_value with string parameter of @"HKLM\Software"

No record is returned.

c. call proc_find_value with string parameter of @"HKLM\\Software" (noted that there are two back slashes in the string)

The record of "HKLM\Software\test" is returned.

-------------

In summary, I inserted @"HKLM\Software\test" but need to pass in @"HKLM\\Software" (double back slash) to find it. It seems strange to me.

Do I miss anything?

Thanks!
Sean

A few questions about Npgsql2 [ reply ]
By: Tao Wang on 2007-11-28 16:43
[forum:1002874]
1. I think "CLASSNAME" in each class is not necessary, we can use "this.GetType().Name" instead. Am I missing anything here?



2. The Mono.Security reference is used for SSL connection. But .Net Framework 2.0 already implement SslStream, is that possible to eliminate Mono.Security dependence by using System.Net.Security.SslStream? And same thing for MD5, maybe using System.Security.Cryptography.MD5 is more natural for .Net 2.0. There are some classes or functions seems could be simplified by taking advantage of .Net 2.0 framework.



3. The recent updated test case for Connection:

[Test]
[ExpectedException(typeof(NpgsqlException))]
public void ConnectionStringWithSemicolonSignValue()
{

NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=44444;User Id=npgsql_tets;Password='j;'");

conn.Open();

}

I cannot understand the case. Should we throw a Exception here?

If yes, how to write connection string which contains a password which contains a semicolon?



4. Missing 3 methods, 1 property in NpgsqlFactory.
public virtual bool CanCreateDataSourceEnumerator { get; }
public virtual DbConnectionStringBuilder CreateConnectionStringBuilder();
public virtual DbDataSourceEnumerator CreateDataSourceEnumerator();
public virtual CodeAccessPermission CreatePermission(PermissionState state);

They are new in .Net 2.0.

5. Maybe we should implement a class NpgsqlConnectionStringBuilder which inherit from DbConnectionStringBuilder, to replace NpgsqlConnectionString. They are really similar and some functions in NpgsqlConnectionString has done in DbConnectionStringBuilder.



6. May be we should have a look on LINQ, there are some code implement LINQ to SQL for postgresql by using npgsql. :
http://code2code.net/DB_Linq/index.html

It's MIT license, is it possible that Npgsql merge the code from the project to make Npgsql support LINQ directly? or a sub-project to do it?



7. Npgsql seems not well support in design mode of Visual Studio. At least not as well as MySQL.Data did. Could that part be improved?

Thanks.

Tao Wang.

Should Npgsql Centralize the resource files? [ reply ]
By: Tao Wang on 2007-11-29 12:50
[forum:1002888]
I think it would be good that if make the resource file centralized. It will much easier for translator and easier to pick an existing string rather than create mew one which actually existing in other resource file.

Newer Messages  Older Messages
Powered By FusionForge