Forum: help

Monitor Forum | Start New Thread Start New Thread
search for string with back slash [ reply ]
By: Sean Zeng on 2007-12-03 18:05

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:

b. FUNCTION proc_find_value(i_value text) as:

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?


A few questions about Npgsql2 [ reply ]
By: Tao Wang on 2007-11-28 16:43
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:

public void ConnectionStringWithSemicolonSignValue()

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



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. :

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?


Tao Wang.

Should Npgsql Centralize the resource files? [ reply ]
By: Tao Wang on 2007-11-29 12:50
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.

Npgsql.csproj and Npgsql.sln bugs. [ reply ]
By: Tao Wang on 2007-11-17 17:34
1. Npgsql.csproj missing include for zh-CN resource file.
When I use Visual Studio open Npgsql.csproj. All zh-CN.resx are exclude from the project.

I create a patch for fix:
=================== CUT BEGIN ===================
Index: Npgsql.csproj
--- Npgsql.csproj (revision 4)
+++ Npgsql.csproj (working copy)
@@ -102,9 +102,9 @@
<Compile Include="Npgsql\NpgsqlConnectorPool.cs">
- <Compile Include="Npgsql\NpgsqlCopyFormat.cs">
- <SubType>Code</SubType>
- </Compile>
+ <Compile Include="Npgsql\NpgsqlCopyFormat.cs">
+ <SubType>Code</SubType>
+ </Compile>
<Compile Include="Npgsql\NpgsqlCopyIn.cs">
@@ -250,6 +250,10 @@
+ <EmbeddedResource Include="Npgsql\NpgsqlCommand.zh-CN.resx">
+ <DependentUpon>NpgsqlCommand.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Npgsql\NpgsqlCommandBuilder.resx">
@@ -278,6 +282,10 @@
+ <EmbeddedResource Include="Npgsql\NpgsqlConnection.zh-CN.resx">
+ <DependentUpon>NpgsqlConnection.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Npgsql\NpgsqlConnectionString.resx">
@@ -302,6 +310,10 @@
+ <EmbeddedResource Include="Npgsql\NpgsqlEventLog.zh-CN.resx">
+ <DependentUpon>NpgsqlEventLog.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Npgsql\NpgsqlException.resx">
@@ -326,6 +338,10 @@
+ <EmbeddedResource Include="Npgsql\NpgsqlParameter.zh-CN.resx">
+ <DependentUpon>NpgsqlParameter.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Npgsql\">
@@ -346,6 +362,10 @@
+ <EmbeddedResource Include="Npgsql\NpgsqlParameterCollection.zh-CN.resx">
+ <DependentUpon>NpgsqlParameterCollection.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Npgsql\NpgsqlReadyState.resx">
@@ -374,6 +394,10 @@
+ <EmbeddedResource Include="Npgsql\NpgsqlTransaction.zh-CN.resx">
+ <DependentUpon>NpgsqlTransaction.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Npgsql\PGUtil.resx">
=================== CUT END ===================

The patch also include the bug for "Missing reference to NpgsqlCopyFormat.cs" which already fix at Revision 1.5.

2. Cannot open the solution file with Visual Studio 2005.

The file looks alright, but I cannot double click it to open with Visual Studio 2005 (it said unrecognized version). I saved a solution file by VS 2005 to see the difference. I found the significant difference is that the new line of Npgsql2.sln is \n (0xA) rather than \r\n (0xD, 0xA). I think that might be the reason.

Can't find custom attr constructor image [ reply ]
By: sai sai on 2007-11-16 10:30

I am using ubuntu+apache+postgresql to develop I contact the pages,errors occur.

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

In the erro_log:
** (/usr/lib/mono/1.0/mod-mono-server.exe:5555): WARNING **: Missing method .ctor in assembly /tmp/daemon-temp-aspnet-0/51f4ab22/assembly/shadow/a232aa5f/5fd7e261_fde5483e/Npgsql.dll, type System.Runtime.CompilerServices.RuntimeCompatibilityAttribute

** ERROR **: Can't find custom attr constructor image: /tmp/daemon-temp-aspnet-0/51f4ab22/assembly/shadow/a232aa5f/5fd7e261_fde5483e/Npgsql.dll mtoken: 0x0a000156
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

I cant not decide the errors happen in the mono runtime or Npgsql.dll.

Can any one help me?Thanks.

NpgsqlConnectionString's performance [ reply ]
By: Tao Wang on 2007-11-17 03:17

When I profiling my code, I found one of a bottle-neck of the code is setting NpgsqlConnection.ConnectionString. I used the profiler to dig in, and found it's the regular expression in NpgsqlConnectionString.ParseConnectionString() cost most time.

Could you use RegexOptions.Compiled for the static regular expressions in NpgsqlConnectionString? It may a little faster.

I think it's important to improve ParseConnectionString()'s performance, since for each DbCommand, I need to create a new DbConnection, and assign a parsed connection string.

One possible solution is caching the parsed connection string (NpgsqlConnectionString object). If it's same connection string, then use the existing parsed result, other than parse it again.

It make sense since, in most case, there are only a few connection string to use, but much more times than that to create a new DbConnection and assign the same connection string.


error: [ reply ]
By: Dmitry Nizinkin on 2007-11-19 11:08
hi, i have method
public void WriteRow()
{ string tmpStrWeight = null;
string tmp_command = null;
if (!f_is_connected)//check connection

tmpStrWeight = f_weigth.ToString();
tmpStrWeight = tmpStrWeight.Replace(",", ".");
tmp_command = String.Format("INSERT INTO tobackup.t_app_log(id, board_number,direction_id, time_best, auto_number, weight,IsCorrect ) VALUES ({0},{1},{2},'{3}','{4}',{5},{6});", f_row_id, BoardNumber(f_lpr_id), DirectionId(f_lpr_id),
ft_time_best, f_auto_number, tmpStrWeight, f_is_good_weigth);
f_command.CommandText = tmp_command;
catch (Exception e)
{ WriteToLog(" e.Message + "tmp_command: " + tmp_command , EventLogEntryType.Error);
and got tis error:
Backend sent unrecognized response type: tmp_command: INSERT INTO tobackup.t_app_log(id, board_number, direction_id, time_best, auto_number, weight,IsCorrect ) VALUES (21308,2,1,'2007-11-19 12:49:11.2650000','Y796EO42',7.86,True);
This method executing then pgsql server send to my application async notification.usially method run without error? but rarely i get error.Any Ideas?

NullReferenceException in Npgsql2 [ reply ]
By: Tao Wang on 2007-11-16 02:31
I run the following code:
command.Connection = this.DB.Factory.CreateConnection();
command.Connection.ConnectionString = this.DB.ConnectionString;
reader = command.ExecuteReader();
if (reader.Read())
obj = ParseReader(reader);
obj = null;

And I got NullReferenceException raise when calling command.ExecuteReader(). The command is DbCommand which created by NpgsqlFactory.

And sometime I got another Exception said command.Connection is not open at same position. I checked the State of the connection at the exception point, it is Closed.

Am I missing anything here?

example for deleting and updating [ reply ]
By: Johannes Holzer on 2007-11-16 01:38

could you please post an example for updating and deleting analog to the "Working with .NET Datasets" in your manual?
I am using IDbDataAdapter and mono's ProviderFactory instead of NpgsqlAdapter. But I think there is not much difference.
I want to perform actions to the database and update viewing like this:

protected void BindData(GridView table, string query, action act)
IDbConnection conn = ProviderFactory.CreateConnectionFromConfig("appSQLConnStr");
IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = query;
IDbCommand selCmd = conn.CreateCommand();
selCmd.CommandText = m_defaultQuery + m_extQuery;

DataSet ds = new DataSet("anyname");

IDbDataAdapter nda = ProviderFactory.CreateDataAdapter(selCmd);

switch (act)
case action.delete: nda.DeleteCommand = cmd;
case action.update: nda.UpdateCommand = cmd;
case action.insert: nda.InsertCommand = cmd;

int i = nda.Update(ds);
table.DataSource = ds.Tables[0];

action is a simple enumeration.
But this code does no deltion in the database. I think something is missing.

Thanks in advance

Npgsql2 may action weird under multi-thread [ reply ]
By: Tao Wang on 2007-11-15 21:02
I got some weird error when I use Npgsql2 under multi-thread circumstance.

1. Got Backend sent unrecognized response type in '\0'
But next time I run, it disappearred.

2. Select SQL may not return all columns.
Once I got an error said there is no field for "chapter_id" in my database table. However, I run the ErrorSQL of NpgsqlException in postgresql directly, I got the exactly what I want. But it's not very often, only a few times.

3. Get Error of other thread.
I have multithread tasks running, thread A just do a selection and the SQL is correct. Thread B do an insert or update command, the SQL violate some constraints. During the running, I got a few times that thread A got NpgsqlException say that it's violates the constraints, however it's impossible, since it's only selection command, can never violate constraints. The exception error must raised from other thread. I got this StackTrace:

at Npgsql.NpgsqlConnector.CheckErrors()
at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications()
at Npgsql.NpgsqlCommand.ExecuteCommand()
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()

My postgresql is a local database server(just for test), it's not a heavy running server. In my case, I only have 6 threads, not so much.

Since I got those errors in just few minutes, I may get more other errors. If I got them, I will follow up this threads. Thanks.

Npgsql2 may action weird under multi-thread

updateBatchSize [ reply ]
By: firealarm firealarm on 2007-10-30 17:59

the function updateBatchSize from the NpgsqlDataAdapter doesn't works?

When I set the value from 1 to 0, I get an error message (error 438, object does not support this property or method).

Any suggestion?

.NET FileLoadException Mono.Security [ reply ]
By: Sebastian Schüler on 2007-11-12 11:21
Hi there,

I just installed the postgreSQL server, and startet to create a program in VB.NET to connect to the Database.

I have already created a link to the Mono.Security.dll and the npgsql.dll so that the functions contained in the npgsql package got available.

This is my Code:
conn = New Npgsql.NpgsqlConnection(connstring)

Now when i compile, and the programm starts to connect to the database i get the following error message:

"Die Datei oder Assembly Mono.Security, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756 oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)"

I'm sorry that the errormessage is in german.

So in english it means, that the Version of the link does not match the included file.
The only thing i did, was to create the link / reference in .NET to the following files:


Somehow in a previous project the same error occured, and was gone after some time, this old project is running without any problem, the connectionstring etc is the same.

Newer Messages  Older Messages
Powered By FusionForge