Forum: help
Monitor Forum | | Help connecting to database from asp.net [ reply ] By: Ryan Reif on 2010-08-17 15:23 | [forum:1006365] |
|
Hi all, I am trying to connect to use the Nglsql and am having issues. I have added a reference to the compiled 4.0 version Npgsql.dll (version 2.0.10.0) in the web app and in my code behind I am importing the namespaces: Imports System Imports System.Data Imports System.Nglsql Intellisense works great. I keep on getting missing source files when I try to debug the program. It is looking for files like Locating source for 'C:\projects\Npgsql2\src\Npgsql\NpgsqlConnection.cs'. Checksum: MD5 {23 b5 2d 52 c 39 e 34 1a 28 da 13 9e 41 7d f1} In the below code, it never gets past the NpgsqlConnection. Dim sql As String sql = "SELECT ""SMSs"" FROM ""SMSs"";" Dim SQLConnect As String SQLConnect = "Server=123.123.123.123;Port=5432;Database=watermissions;Userid=username;Password=pass;Pooling=true;MinPoolSize=1;MaxPoolSize=20;ConnectionLifeTime=15" Dim conn As NpgsqlConnection = New NpgsqlConnection(SQLConnect) conn.Open() ... Should it do this with the binary version? Could someone please help me resolve this issue? I have searched online a bit but I haven't been able to find anything addressing this. |
|
RE: Help connecting to database from asp.net [ reply ]
By: Josh Cooley on 2010-08-18 02:27[forum:1006368]
The namespace is Npgsql, not System.Npgsql. But if you are getting itellisense, then that's likely just a typo in this post.
The missing source files is what you get when you have the assembly and pdb files but don't have the source installed on your machine. It's not an issue unless you want to debug Npgsql.
Can you share any exception you are getting when trying to open a connection?RE: Help connecting to database from asp.net [ reply ]
By: Ryan Reif on 2010-08-18 15:05[forum:1006371]
Hi Josh,
Thanks for the reply. Good observation, System.Npgsql is a typo. It is Npgsql in my source.
This is occurring when I have set a break point and am stepping through the source to check that everything is working correctly. It will go through without errors with the debug on when a breakpoint is not set, but I am not getting the results displayed in my gridview, so I am trying to figure out the issue.
The screen "No source available" shows up many times. I have to hit F11 around 50 times to go through it.
Here is a typical screenshot:
http://rdb.watermissions.org/images/npgsqldisassembly.jpg
Here are some of the stack locations it is referring to:
http://rdb.watermissions.org/images/stacklocations.png
The source file information stays the same during each step and the call stack location is the only text that appears to change.
So as far as I can tell, there is technically no exception, but I can't get display my results...
RE: Help connecting to database from asp.net [ reply ]
By: Josh Cooley on 2010-08-18 15:17[forum:1006372]
Try removing the pdb files from your bin directory. That may eliminate the "No source available" error. If it doesn't, then you need to change the options under debugging -> general and check "Enable Just My Code".
Try your query in pgadmin or another tool to verify your query produces what you expect.RE: Help connecting to database from asp.net [ reply ]
By: Ryan Reif on 2010-08-18 17:36[forum:1006374]
I removed the pdb files. They are recreated on every compile and it continues to show the messages when debugged. I looked at my options and "Enable Just My Code" is checked.
I tried the query in pgadmin and it works.
I found a error in my CSS that prevented the gridview from showing up. The site now displays the data correctly when run without debugging or with debugging and no breakpoints. Like before, when the breakpoints are in there, it looks for the source files. Once those are stepped over, it continues without an exception. I am perplexed, but satisfied it is working for now. Thanks for your assistance!
| EF 4 ctp 4 support [ reply ] By: Raúl Andrés Duque Murillo on 2010-08-17 04:47 | [forum:1006363] |
| The DatabaseExists() method is not yet supported ... any plan to support it? | |
RE: EF 4 ctp 4 support [ reply ]
By: Josh Cooley on 2010-08-18 02:24[forum:1006367]
We would like to support this, but we currently don't have a schedule for a release supporting this. RE: EF 4 ctp 4 support [ reply ]
By: Raúl Andrés Duque Murillo on 2010-08-18 10:17[forum:1006370]
Thanks Josh for your soon answer.
| Insert, delete, update DB from Visual C# [ reply ] By: Pham Son on 2010-08-13 17:16 | [forum:1006354] |
|
I use PostgresSQL. Nơ, I want to insert, delete, update database from Visual C#. But, I don't know. I connected successful PostgresSQL & Visual C# Can you help me??? Thanks. |
|
RE: Insert, delete, update DB from Visual C# [ reply ]
By: Josh Cooley on 2010-08-14 18:07[forum:1006355]
Have you looked at the User's Manual? It has several examples some of which include inserts and updates. You can find examples of plain SQL, stored procedures, and using DataSets. RE: Insert, delete, update DB from Visual C# [ reply ]
By: Pham Son on 2010-08-15 00:59[forum:1006358]
I don't knows, how does it find??? you can say about it. Thanks!!! RE: Insert, delete, update DB from Visual C# [ reply ]
By: Francisco Figueiredo jr. on 2010-08-15 03:51[forum:1006359]
http://manual.npgsql.org
| SET SSL_RENEGOTIATION_LIMIT [ reply ] By: J Verheyden on 2010-08-10 06:53 | [forum:1006324] |
| In version 2.0.10 the NpgsqlConnection will automaticly send the SET SSL_RENEGOTIATION_LIMIT to 0 after connect (i have SSL on preferred). (Correct?) In my case I'm running a production and test server with postgresql 8.4.1. So the set call will return an error and Npgsql will throw an error on connection.open() which is unacceptable in our situation, will this be fixed in later releases or is there a patch or will I have to recompile the dll myself to disable this set call? Please try to keep backwards compatibility. | |
RE: SET SSL_RENEGOTIATION_LIMIT [ reply ]
By: Francisco Figueiredo jr. on 2010-08-12 02:59[forum:1006346]
Hi!
Which error are you getting?
It is strange you are getting any error. We set this parameter inside a try catch block:
/*
* Try to set SSL negotiation to 0. As of 2010-03-29, recent problems in SSL library implementations made
* postgresql to add a parameter to set a value when to do this renegotiation or 0 to disable it.
* Currently, Npgsql has a problem with renegotiation so, we are trying to disable it here.
* This only works on postgresql servers where the ssl renegotiation settings is supported of course.
* See http://lists.pgfoundry.org/pipermail/npgsql-devel/2010-February/001065.html for more information.
*/
try
{
NpgsqlCommand commandSslrenegotiation = new NpgsqlCommand("SET ssl_renegotiation_limit=0", this);
commandSslrenegotiation.ExecuteBlind();
}
catch {}
RE: SET SSL_RENEGOTIATION_LIMIT [ reply ]
By: J Verheyden on 2010-08-12 04:23[forum:1006347]
your not allone, i don't understand why the debugger halts on it.
But is it possible to disable it for perfomance reasons?
RE: SET SSL_RENEGOTIATION_LIMIT [ reply ]
By: J Verheyden on 2010-08-12 11:33[forum:1006348]
Ok, I overreacted apperently.
I checked my settings and my debugoptions where set to break on postgress-exceptions.
The error message is thrown and caught whenever a connection is made (or remade in a connectionpool) so i'll have to reimplement it to limit the occurence of this error.
| npgsql and date types [ reply ] By: horvath imre on 2010-04-20 16:21 | [forum:1005970] |
|
hi, please advise me on this issue. I use npgsql to connect to the postgresql server. My application is written in vb.net. In one table I store date fields too, no problem. If I open up the table, I see the date values like 2010-04-20, that's ok. Originally, I send the date values in this format: 2010.04.20 to the server, so this is ok too. BUT, when I read the dates via npgsql.dataadapter, I get date values like 2010.04.20 0:00:00 And this isn't ok. I tried to remove the nulls, f.e. Format(date value,"yyyy.mm.dd"), no succes. I get an exception (whitout stopping the app): A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll And the other rows don't show up too in the datagridview. Why this formatting trouble? How can I solve it? |
|
RE: npgsql and date types [ reply ]
By: Liam Ho on 2010-08-05 02:40[forum:1006258]
Hi guys I am having trouble with this as well. Can anyone give use some details of a solution please? Is this a known bug with Npgsql?
Thanks
LiamRE: npgsql and date types [ reply ]
By: Josh Cooley on 2010-08-05 16:43[forum:1006259]
Do you have Use Extended Types = true in your connection string? If so, you're going to have to convert the Npgsql types to something that are more culture friendly. The Npgsql types are designed for data access and not for display. RE: npgsql and date types [ reply ]
By: Liam Ho on 2010-08-05 22:35[forum:1006260]
Hi Josh
Thanks for the quick reply. I tried the use extended types however it did not work. The issue was a bug in Npgsql. I have just updated to the latest version 2.10.0 that was released a few days ago and it fixed this issue.
Thanks
Liam
| OrderByDescending(s => s.Date).FirstOrDefault [ reply ] By: the veeroo on 2010-07-26 09:17 | [forum:1006230] |
|
Hello I have a problem with my Linq-to-entities query with npgsql provider. I have 3 tables: Order, OrderStatus and OrderStatusDict (dictionary). OrderStatus is some kind of changeLog - every order's status change is added to the OrderStatus table with its actual date and new status. I need to get all orders, which status.OrderStatusDict.OrderStatusName == "Pending", so im doing this this way: var lst = (from o in db.Order where o.OrderStatus .OrderByDescending(s => s.Date) .FirstOrDefault() .OrdereStatusDict.OrderStatusName == "Pending" select o).ToList(); And I get an exception: An error occurred while preparing the command definition. See the inner exception for details. Data:{System.Collections.ListDictionaryInternal} Inner exception: {"The method or operation is not implemented."} And it looks that OrderByDescending kills my query, cause if I comment .OrderByDescending(s => s.Date) Everything works fine, but I get the oldest OrderStatus from db :/ Can u help me? Is this a provider's cause or EF problem? Do you have any ideas I could gain this other way? |
|
RE: OrderByDescending(s => s.Date).FirstOrDefault [ reply ]
By: Josh Cooley on 2010-07-28 00:01[forum:1006240]
I can only guess based on the message, but I suspect this is due to the framework generating a query than needs cross apply support. The only solution is to rewrite the linq statement.
Here's an idea on something to test. There may be other variations you can try. If you haven't moved to .NET 4.0, you might consider that as well. Microsoft has simplified the way queries are generated and it may be easier to find a variation that doesn't have this problem.
var lst = (from o in db.Order
from s in o.OrderStatus
where s.Date == o.OrderStatus.Max(os => os.Date) &&
s.OrderStatusDict.OrderStatusName == "Pending"
select o).ToList();
| Nullpointer in NpgsqlDatareader [ reply ] By: Stefan Nicodem on 2010-07-01 07:33 | [forum:1006183] |
|
After rewriting the database access code of my application I came across this error while executing a COUNT query with ExecuteScalar(). Tha application is multithreaded (about 11 to 25 threads at a time) and each thread does alot of queries (about 50 to over 1000). It are mostly insert statements and all of those seem to go fine. I also read here about the problem with the ReadInt32() and ReadInt16() buffers, so I'm using the latest version from CVS. That's the story, now the problem: I traced the error by debugging in visual studio express, and found out it is caused by calling _connection.EmergencyClose() in NpgsqlData |
|
RE: Nullpointer in NpgsqlDatareader [ reply ]
By: Stefan Nicodem on 2010-07-01 07:36[forum:1006184]
- Sorry, posted accidentially -
Continued:
I traced the error by debugging in visual studio express, and found out it is caused by calling _connection.EmergencyClose() in NpgsqlDataReader line 1333.
Here's the call stack:
Npgsql.dll!Npgsql.ForwardsOnlyDataReader.CleanUp(bool finishedMessages = false) Line 1333
Npgsql.dll!Npgsql.ForwardsOnlyDataReader.Close() Line 1348 + 0xa bytes
[External Code]
Npgsql.dll!Npgsql.ForwardsOnlyDataReader.Dispose(bool disposing = true) Line 1288 + 0xc bytes
[External Code]
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteScalar() Line 715 + 0x75 bytes
Npgsql.dll!Npgsql.NpgsqlConnector.CheckParameter(string paramName = "escape_string_warning") Line 998 + 0xb bytes
Npgsql.dll!Npgsql.NpgsqlConnector.CheckStringConformanceRequirements() Line 1045 + 0x36 bytes
Npgsql.dll!Npgsql.NpgsqlConnector.UseConformantStrings.get() Line 1051 + 0x2c bytes
Npgsql.dll!Npgsql.NpgsqlCommand.PassParam(System.Text.StringBuilder query = {System.Text.StringBuilder}, Npgsql.NpgsqlParameter p = {Npgsql.NpgsqlParameter}) Line 940 + 0x15 bytes
Npgsql.dll!Npgsql.NpgsqlCommand.GetClearCommandText() Line 1062 + 0x24 bytes
Npgsql.dll!Npgsql.NpgsqlCommand.GetCommandText() Line 891 + 0x30 bytes
Npgsql.dll!Npgsql.NpgsqlQuery.WriteToStream(System.IO.Stream outputStream = {System.IO.BufferedStream}) Line 53 + 0xd bytes
Npgsql.dll!Npgsql.NpgsqlReadyState.QueryEnum(Npgsql.NpgsqlConnector context = {Npgsql.NpgsqlConnector}, Npgsql.NpgsqlCommand command = {Npgsql.NpgsqlCommand}) Line 64 + 0x1e bytes
Npgsql.dll!Npgsql.NpgsqlConnector.QueryEnum(Npgsql.NpgsqlCommand queryCommand = {Npgsql.NpgsqlCommand}) Line 294 + 0x19 bytes
Npgsql.dll!Npgsql.NpgsqlCommand.GetReader(System.Data.CommandBehavior cb = SingleResult | SingleRow | SequentialAccess) Line 611 + 0x10 bytes
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteScalar() Line 712 + 0xd bytes
Plog2.exe!Plog2.RetrieveCC.StartNextAutoRetrieve(bool GPRS = false) Line 357 + 0xb bytes
Plog2.exe!Plog2.RetrieveCC.retrTemp_RetrieveReadyEvent(Plog2.Order order = {Plog2.Order}) Line 593 + 0xa bytes
Plog2.exe!Plog2.Retrieve.FireReadyEvent() Line 109 + 0x14 bytes
Plog2.exe!Plog2.Retrieve.RetreeverDisconnected() Line 1014 + 0x8 bytes
Plog2.exe!Plog2.Retreever2.Retreever2DLL_OnCloseConnection(int iConnectionID = 1019, int iStatus = 3) Line 145 + 0xa bytes
Retreever2DLL.dll!Retreever2DLL.Retreever2DLL.FireCloseConnectionEvent(int iConnectionID = 1019, int iStatus = 3) Line 150 + 0x14 bytes
Retreever2DLL.dll!Retreever2DLL.Retreever2DLL.FireCloseConnectionDetailedEvent(int iConnectionID = 1019, int iStatus = 3, ushort ushortCAPIerrorCode = 0) Line 174 + 0xb bytes
Retreever2DLL.dll!Retreever2DLL.Connections.ConnectionsCC.RemoveConnection(Retreever2DLL.Connections.AConnection remConnection = {Retreever2DLL.Connections.TCPconnection}) Line 351 + 0x33 bytes
Retreever2DLL.dll!Retreever2DLL.Connections.TCPconnection.RemoveConnection() Line 795 + 0x15 bytes
Retreever2DLL.dll!Retreever2DLL.Connections.TCPconnection.SendPacketSerie() Line 144 + 0xb bytes
Retreever2DLL.dll!Retreever2DLL.Connections.TCPconnection.DataThreadFunc() Line 354 + 0x8 bytes
[External Code]
Can anyone point me in the direction of what I am doing wrong to cause this or if this is a bug?
I already tested serveral 2.x versions of Npgsql and I seem to always get an error (differs with older versions). But the funny thing is that Npgsql 1.0.1 doesn't seem to have this problem...RE: Nullpointer in NpgsqlDatareader [ reply ]
By: Stefan Nicodem on 2010-07-01 08:29[forum:1006185]
I just tested with the Pooling=false connection string option and this also gives me the same error on the exact same line.
It just bypasses the getting connection from pool like you expect., but then also generates a nullpointer exception.RE: Nullpointer in NpgsqlDatareader [ reply ]
By: Stefan Nicodem on 2010-07-01 11:37[forum:1006186]
After testing some more with Npgsql 1.0.1 I also get an error:
"Queue empty."
at System.Collections.Queue.Dequeue()
at Npgsql.NpgsqlConnectorPool.TimerElapsedHandler(Object sender, ElapsedEventArgs e) in c:\\Desenvolvimento\\Npgsql1.0-src\\Npgsql\\src\\Npgsql\\NpgsqlConnectorPool.cs:line 94
at System.Timers.Timer.MyTimerCallback(Object state)
This happens when using the pooling functionality.
Only thing that keeps working is Npgsql 1.0.1 with Pooling=false
RE: Nullpointer in NpgsqlDatareader [ reply ]
By: Josh Cooley on 2010-07-03 19:38[forum:1006195]
If the EmergencyClose line is causing your problems, it's because your thread has been aborted and we are trying to safely clean up. We work hard to ensure this works cleanly since IIS will kill threads that take too long, but your code is already going to die.
Any ideas why your thread is being aborted?RE: Nullpointer in NpgsqlDatareader [ reply ]
By: Stefan Nicodem on 2010-07-20 06:26[forum:1006220]
That is strange seeing when the problem occurs the thread is in the middle of his life. It reports back to the GUI that his database connection is suddenly not working and that it cannot execute the queries that are waiting.
I need to look into it a little further but the only way my threads are aborted is when killing the application and when a timeout occurs (and with a timeout there is only 1 insert query).
| Passing row as parameter [ reply ] By: Matt . on 2010-07-05 20:36 | [forum:1006203] |
|
I'm not sure the right way to ask this question, so I apologize for anything that's confusing. Currently I'm not using the Entity Framework (I don't know it well enough to use it). I have a stored procedure and I'd like to pass rows as parameters. Here's a contrived example (and pseudo-code) of what I'm trying to do: I have a table users: CREATE TABLE users ( id integer username text date_added timestamp ); Right now, I have a stored procedure that takes a single username and date and does the insert. When I need to insert multiple users, I end up having to iterate in my code: foreach (User user in users) { cmd.Parameters[0].Value = user.name; cmd.Parameters[1].Value = user.date; cmd.ExecuteScalar(); } where cmd is an NpgsqlCommand that calls the stored procedure add_user: add_user(@username text, @date_added timestamp) The problem is, when I need to add thousands of users, this is slow. I'd like to instead pass the array of users: add_users(@users _users); Then the stored procedure can do the processing/work. I'm sorry if that doesn't make sense, but that's the general idea of what I'm going for. Any suggestions would be greatly appreciated. |
|
RE: Passing row as parameter [ reply ]
By: Josh Cooley on 2010-07-10 03:10[forum:1006214]
I think you are looking for NpgsqlCopyIn. See the user's manual for information on using copy functionality.
http://npgsql.projects.postgresql.org/docs/manual/UserManual.html
| Entity framework: how to use views/functions? [ reply ] By: anton Hughes on 2010-07-05 12:35 | [forum:1006199] |
|
Hi I'm wanting to use EF in my current project, but I see that it cannot work with geometry types, so I thought I would encapsulate the logic in a view or custom function. However, the views and functions do not get generated into the c# classes. I have one view and one custom function and I cannot see either of these referenced in the generated c# code. What do I need to do to call a view or function from EF? Thanks |
|
RE: Entity framework: how to use views/functions? [ reply ]
By: Josh Cooley on 2010-07-10 03:07[forum:1006213]
Npgsql can't determine the primary key for views and so EF can't model them as entities. If you manually create a model, then it will work. But there's no automated support in 3.5 since there's no primary key.
| Unable to read large bytea field data [ reply ] By: Casper Jasmine on 2010-07-08 12:51 | [forum:1006209] |
|
Good day to all. I am facing getting NotSupportedException while reading large bytea field data. I am new to the forum, if this issue is already discussed, kindly point me there. Details: OS: Windows XP sp3 RAM: 3GB Postgres: 8.4 (localhost) Npgsql: 2.0.6 I am able to insert large data using prepared statement <code> using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgre;Password=postgre;Database=test;")) { conn.Open(); using(NpgsqlCommand command = new NpgsqlCommand("insert into screenshotstore (screenshot, filesize) values (:screenshot, :filesize)", conn)) { command.Parameters.Add(new NpgsqlParameter("screenshot", NpgsqlDbType.Bytea)); command.Parameters.Add(new NpgsqlParameter("filesize", NpgsqlDbType.Integer)); command.Prepare(); FileStream fs = new FileStream(@"c:\test.bmp", FileMode.Open); // 30MB file int iFileSize = Convert.ToInt32(fs.Length); byte[] bytData = new byte[iFileSize]; fs.Read(bytData, 0, iFileSize); fs.Close(); command.Parameters[0].Value = bytData; command.Parameters[1].Value = iFileSize; command.ExecuteNonQuery(); } conn.Close(); } } </code> For reading bytea field data, I have used DataAdapter with no luck. Later I tried with DataReader with no luck and ExecuteScalar with no luck. Following is the code I am using to read large bytea <code> using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgre;Password=postgre;Database=test;")) { conn.Open(); using (NpgsqlCommand command = new NpgsqlCommand("select screenshot from screenshotstore where id = 12", conn)) { Byte[] rawData = (Byte[])command.ExecuteScalar(); int fileSize = rawData.Length; FileStream fs = new FileStream(@"c:\test1.bmp", FileMode.OpenOrCreate, FileAccess.ReadWrite); fs.Write(rawData, 0, fileSize); fs.Close(); fs.Dispose(); } conn.Close(); } </code> A NotSupportedException is raised with message <b>Backend sent unrecognized response type: 0</b>. Please tell me how to read large bytea field data. Regards, Casper |
|
RE: Unable to read large bytea field data [ reply ]
By: Francisco Figueiredo jr. on 2010-07-08 18:14[forum:1006210]
You should use prepared statements too when reading data so Npgsql will be able to optimize data transfer.
It is strange you are getting the unrecognize response type 0. Are you using ssl connections?
I hope it helps.
RE: Unable to read large bytea field data [ reply ]
By: Casper Jasmine on 2010-07-09 05:08[forum:1006211]
Thank you very much. Your suggestion is helped me. I was under the impression that prepared statement is meant for insert/update. Thank you once again.
Have a nice day,
Casper
| Backend sent unrecognized response type: \0 [ reply ] By: Washington Junior on 2010-06-30 23:48 | [forum:1006179] |
|
Hi, guys I'm having a issue with npgsql ("Backend sent unrecognized response type: \0"), but only on Windows 7 system. All returned records from a query are transformed in objects by my own relational-object class (called GSPersistence). Having said that, here is what happens: I'm not using multiple threads, but I fill a DataGridView with my objects that have some properties which may access others objects. I think that the problem is that when DGV is showing the objects, properties that access others objects (which are created with the return of a query from PostgreSQL) may be causing something like "multiple threads". Imagine showing 20 objects that have at least 3 properties that need a query to be filled and you'll have 60 queries running. On GSPersistence I'm using npgsql 1.0, but I already tried to switch to version 2.0 and the same problem happens (and even often). And this issue doesn't happen on Windows XP SP2 or Windows 98 SE, only on Windows 7 (haven't tried on Vista). My software is running on 20 machines, and the problem happens only on the 3 machines with Win7 (there were 4, but one of them I moved to WinXP). All others operations works perfectly, except for showing data on a DataGridView, which sometimes works and sometimes doesn't. Does anybody have a tip of what should I do? (Besides moving all machines to WinXP... :D) Thanks to all. Junior |
|
RE: Backend sent unrecognized response type: \0 [ reply ]
By: Josh Cooley on 2010-07-01 02:25[forum:1006180]
I run windows 7 for development and haven't seen this win 2.0. I've not worked with the 1.0 version in a long time. Did you just install the 2.0 version of Npgsql or did you recompile your app? There were breaking changes that require you to at least recompile your application.
Are you closing your readers before executing another command on the same connection?RE: Backend sent unrecognized response type: \0 [ reply ]
By: Washington Junior on 2010-07-01 03:11[forum:1006182]
Hi Josh,
My development machine is also with Win7, and as my application does not use Npgsql directly (GSPersistence does), I've created a temporary fork (name GSPersistence2) using Npgsql 2.0.9 and have referenced it in a copy of my application project.
And yes, I did notice the error message "There is already an open DataReader associated with this Command which must be closed first." but in this particular case this message doesn't appear (although I saw it in other operations after this change). Could this affect in any way? I'll try to fix it and see if it makes a difference.
Thanks.RE: Backend sent unrecognized response type: \0 [ reply ]
By: Francisco Figueiredo jr. on 2010-07-01 14:03[forum:1006187]
Hi, Washington!
We have a problem with Npgsql and multiple threads even not using NpgsqlConnection at the same time.
Would you mind to give a try with 2.0.8?
Thanks in advance.
RE: Backend sent unrecognized response type: \0 [ reply ]
By: Washington Junior on 2010-07-02 11:35[forum:1006190]
Hi, Francisco
I'm using Npgsql 2.0.9 and the same thing happens. Sometimes works, others I get the error message and sometimes it just freezes on "da.Fill(ds)" without any message.
Should I try to downgrade to 2.0.8?
Thanks!RE: Backend sent unrecognized response type: \0 [ reply ]
By: Francisco Figueiredo jr. on 2010-07-03 17:52[forum:1006192]
Yes, please, try downgrading to 2.0.8.
Or you can try compiling Npgsql from cvs which has the problem from 2.0.9 fixed.
I hope it helps.
RE: Backend sent unrecognized response type: \0 [ reply ]
By: Washington Junior on 2010-07-05 14:46[forum:1006200]
Hi again,
Yes, it works perfectly with Npgsql 2.0.8 (no freezing or error message). This is a specific problem with 2.0.9 or will be fixed in the next release?
Now I can consider moving from Npgsql 1 to 2. :D
Thank you very much!
WashingtonRE: Backend sent unrecognized response type: \0 [ reply ]
By: Francisco Figueiredo jr. on 2010-07-05 18:25[forum:1006202]
I'm glad to hear that.
Yes, it is a problem with 2.0.9 which is already fixed in cvs.
This fix will be on our next release.
| Connection Timeout Exception [ reply ] By: Tindo Ras on 2010-06-24 09:26 | [forum:1006167] |
|
Hi Guys Ive been using postgres for about two years now. For a while ive been tormented by the above mentioned exception. Now this exception hangs the whole application, and sometimes the OS. In client server environment with about 12 client machines each machines hangs 2 to 3 times a day, all at diffrent times. All machines connect thru the super user postgres. What can i do to stop the application from hanging? Anyone with a similar set up can assit with thier implementation Thanx in advance |
|
RE: Connection Timeout Exception [ reply ]
By: Bernd Pinter on 2010-06-24 14:53[forum:1006168]
do you have a little test-code for us?
do you (expicit) catch the exception(s) in your code?
bernd.RE: Connection Timeout Exception [ reply ]
By: Tindo Ras on 2010-06-24 16:36[forum:1006170]
Some sample code:
NpgsqlConnection Connection = new NpgsqlConnection();
Connection.ConnectionString = Shared.ConnectionString;
NpgsqlCommand Command = new NpgsqlCommand();
Command.Connection = Connection;
try
{
Connector.LocalLog(command);
Command.Connection = Connection;
Command.CommandText = command;
if (Connection.State != ConnectionState.Open)
{ Connection.Open(); }
int i = Command.ExecuteNonQuery();
if (i == -1)
i++;
rt = i;
}
catch (Exception ex)
{
new SystemLog(Log.LogType.DBError, ex.Message, "", command);
}
finally { try { Connection.Close(); } catch { } Connection.Dispose(); Command.Dispose(); }
Basically that the general structure. I have a class that handles all database connectivity.RE: Connection Timeout Exception [ reply ]
By: Bernd Pinter on 2010-06-25 06:38[forum:1006171]
mhhh - not that bad.
But what will happen if you run into an exception in your code:
finally {
try {
Connection.Close();
} catch { }
Connection.Dispose();
Command.Dispose();
}
You dispose first the Connection- and after that the Command-Object. But the Command-Object holds a reference to the (allready disposed) Connection. So i guess that Command.Dispose() also throws an Exception, which is unhandled...
Try to exchange these two disposing lines. Or simply remove them from your source - i'll nearly never dispose objects by myself (except in some rare situation - but this codefragment here isn't one of these situations)...
| Search backwards from last record [ reply ] By: Richard Ford on 2010-06-07 12:07 | [forum:1006126] |
|
Hello everyone! I have only recently downloaded npgsql, having previously been a complete database newbie, but have got to grips with it pretty well. The one thing that remains a problem for me is ordering my search. I am making a very large database to search, but when I do my searches it is generally the most recent records that I am interested in, so I really need to search from the end of the table(s). I also need to limit my searches to the last x results. Now I have no problem with LIMIT 100 for limiting my results, it's the other issue that could be a problem. I have seen ORDER BY column_name DESC, the thing is my table will be in perfectly correct order already so it seems to me that using ORDER BY DESC might be a time consuming overhead that I could well do without, as this will have to turn the complete table upside down, and timing will be an important factor in my application. If I could just search backwards from the last record then that is all I need to do. Is this possible please? Many thanks |
|
RE: Search backwards from last record [ reply ]
By: Josh Cooley on 2010-06-16 01:44[forum:1006152]
I don't believe you can count on your records staying in the same order in your table. There may be some trick to get something faster, but an index and an order by desc would be the way I'd recommend solving this problem. RE: Search backwards from last record [ reply ]
By: Bernd Pinter on 2010-06-24 15:01[forum:1006169]
as josh said before: don't count on the (physical) order of any database-table on any database-system!!
Typically tables are NOT realy ordered (an exception to this is e.g. a Clustered Index in MS-SQLServer). Even if your table has the right physical order, a VACUUM or something similar can destroy your physical order in the table and then your are doomed...
So your only chance is an ORDER BY in your query.
bernd.
| Preparing array bug [ reply ] By: xMoMx on 2010-06-13 10:37 | [forum:1006146] |
|
Just wondering if anyone is looking into this? http://pgfoundry.org/forum/message.php?msg_id=1006145 |
|
RE: Preparing array bug [ reply ]
By: Francisco Figueiredo jr. on 2010-06-13 20:47[forum:1006147]
Hi!
Arrays with prepared statements are currently broken. Please, if possible, use non prepared statements.
We are working on it.
Sorry for this problem.
RE: Preparing array bug [ reply ]
By: Francisco Figueiredo jr. on 2010-06-24 05:03[forum:1006166]
Hi!
This is now fixed in cvs. Please, give it a try and let us know if you have any problem.
Thanks in advance.
| Array and prepared statement [ reply ] By: Raoul Cadei on 2010-03-19 16:45 | [forum:1005873] |
|
Hello, I'm presently having troubles trying to insert a Double[] and an Int64[] into a table. Table fields are declered in the following way: temp_values DOUBLE PRECISION ARRAY [8192] NOT NULL, time_values BIGINT ARRAY [8192] NOT NULL, and the code that is trying to do the insert is the following: ............ command3.Parameters.Add(new NpgsqlParameter("PARAM6", NpgsqlDbType.Array | NpgsqlDbType.Double)); command3.Parameters.Add(new NpgsqlParameter("PARAM7", NpgsqlDbType.Array | NpgsqlDbType.Bigint)); ............ command3.Prepare(); ............ command3.Parameters[6].Value = new Double[] {1.2d, 1.3d}; command3.Parameters[7].Value = new Int64[] { 1, 3 }; ............ When the line command3.ExecuteNonQuery(); is executed, application stop working and I can see in PostgreSQL logs the message: ERROR: array value must start with "{" or dimension information Does any good soul have a working example or (better) some hint or correction to my work? This thing is driving me crazy! Many thanks in advance, regards. Raoul |
|
| Using variables in sql insert commands? [ reply ] By: Arya Farzan on 2010-06-17 07:50 | [forum:1006154] |
|
Hello I'm new to Npgsql and I was reading the help guide, I did find static insert commands, but did not find examples which worked with variables. How can I do that with Npgsql? Best Regards! |
|
RE: Using variables in sql insert commands? [ reply ]
By: Francisco Figueiredo jr. on 2010-06-17 17:40[forum:1006155]
You may check "Using parameters in a query" section.
There you'll find an example about using parameters in queries.
I hope it helps.
| Npgsql 2.0.9 - incorrect generated sql query [ reply ] By: Leszek ************** on 2010-06-15 08:46 | [forum:1006148] |
|
Hi, it seems to be a problem while Npgsql 2.0.9 generates sql statement from the following LINQ query: db.Users.Where(u => (((u.StatusId == (int)UserStatus.Active) && u.DisplayNameInResults && u.UserDetailsEF.Locality.ToLower().Contains(locality.ToLower())))).OrderBy(u => u.UserDetailsEF.Locality).ThenBy(u => u.Depth).ThenBy(u => u.Name).ThenBy(u => u.Nick) It produces sql query (see below) where we get an errror (syntax error at or near "FROM"): SELECT "GroupBy1"."A1" AS "C1" FROM (SELECT CAST (Count(1) AS int4) AS "A1" FROM (SELECT FROM "public"."users" AS "Extent1" LEFT OUTER JOIN "public"."user_details" AS "Extent2" ON "Extent1"."user_id"="Extent2"."user_id" LEFT OUTER JOIN "public"."user_details" AS "Extent3" ON "Extent2"."user_id"="Extent3"."user_id" WHERE ((5="Extent1"."status_id") AND ("Extent1"."display_name_in_results"=TRUE)) AND ((position(lower('city_name') in lower("Extent3"."locality"))) >0)) AS "Filter1" LEFT OUTER JOIN "public"."user_details" AS "Extent4" ON "Filter1"."user_id"="Extent4"."user_id") AS "GroupBy1" Do you know why it happens? |
|
RE: Npgsql 2.0.9 - incorrect generated sql query [ reply ]
By: Josh Cooley on 2010-06-16 01:57[forum:1006153]
This is already fixed in CVS. If you want to pull down the latest and test it out, you should no longer have this problem with the generated SQL.
This is happening because of a missed case in filtered joins in generating the SQL. The inner query that has no column list does not contain any columns used in the next level of the projection. This resulted in an empty column list. The CVS fix also took into account the where clause in building the column list.
| Npgsql 2.0.9 Issues with EF 4 [ reply ] By: Charlie Biggs on 2010-04-16 16:01 | [forum:1005944] |
| When I use Npgsql 2.0.9 with a current application I have had running for a long time using Npgsql 2.0.8, I am get GetOrdinal errors in my LINQ to Entities statements. I tried to with both flavors of Npgsql 2.0.9 (Npgsql2.0.9-bin-ms.net4.0.zip and Npgsql2.0.9-bin-ms.net3.5sp1.zip). What is the different between the two packages? Is one for EF 4 (.NET 4) and the other one is for EF 1 (.NET 2)? I had to go back to using Npgsql2.0.8-bin.ms.net3.5sp1.zip order of my application not to get the GetOrdinal when running the application. | |
| Parameters with a CIText column [ reply ] By: Allen Vachon on 2010-05-13 13:19 | [forum:1006057] |
|
Hi, I'm trying to use a CIText column type (contrib) and would like it to work without casting or as code sample 1. Is it possible? Thanks Code sample 1: Simple and ok NpgsqlCommand mTest = new NpgsqlCommand("select 'allo' = 'Allo'::citext", MyConnection); bool mRes1 = (bool)mTest.ExecuteScalar(); Code sample 2: Parameters and not working NpgsqlCommand mTest2 = new NpgsqlCommand("select :Allo = 'Allo'::citext", MyConnection); mTest2.Parameters.Add(new NpgsqlParameter("Allo", DbType.String)); mTest2.Parameters[0].Value = "allo"; bool mRes2 = (bool)mTest2.ExecuteScalar(); |
|
RE: Parameters with a CIText column [ reply ]
By: Francisco Figueiredo jr. on 2010-05-13 13:44[forum:1006058]
Hmmm, we don't have support for this type.
One workaround you can do today is to set the parameter types as DbType.Object. This will make Npgsql not use any cast at all.
I hope it helps.
RE: Parameters with a CIText column [ reply ]
By: Allen Vachon on 2010-05-13 14:04[forum:1006059]
Hi Francisco,
Thanks for your quick answer. I tried it and did not work.
Note: When debugging, the DbType was string?
Any plan in the future to support that type through npgsql parameter type?RE: Parameters with a CIText column [ reply ]
By: Francisco Figueiredo jr. on 2010-05-14 13:44[forum:1006061]
Hmmm, strange. It should work.
Can you enable Npgsql logging (check user manual)
and verify which command Npgsql is sending?
The DbType should be DbType.Object.
Hmm, I think I know what is happening... You have to specify the DbType *after* setting the value.
This is because Npgsql will infer the DbType when you set the value.
Try it and let me know if it works.
We don't have any plans about this type. Please, fill a feature request about this type so we can track it down.
Thanks in advance.
| Cast-Exception with NpgsqlTimeStamp [ reply ] By: Bernd Pinter on 2010-04-27 13:01 | [forum:1006004] |
|
Hey! We run into a cast-exception with Npgsql >= 2.0.8. It'll happen when we try to copy (assign) the content of a NpgsqlTimeStamp into a DateTime class-instance. This bug new in 2.0.8 (and also happens in 2.0.9) but it didn't occur in 2.0.5. We found this Timestamp-Bug deep inside within a library of our company. However, i build a little test-program (copy out all necessary code-fragments into a single file) to verify the bug. Plattform: C# with MS .Net 3.5SP1, VisualStudio 2008 I don't know if this forum is the right place for this message and i also don't know where to post my test-program. Please help! Thx! best, Bernd Pinter |
|
RE: Cast-Exception with NpgsqlTimeStamp [ reply ]
By: Bernd Pinter on 2010-04-28 14:01[forum:1006009]
Ok, here (again) is the source-code of my test-program to verify the Timestamp2Datetime bug.
Plattform: MS .Net3.5SP1, VS2008; PostgreSQL 8.4.2; NPGSQL 2.0.8, 2.0.9 (worked in 2.0.5)
best, Bernd
======================= C# Test-Program .Net 3.5SP1 =======================
using System;
using System.Data;
using Npgsql;
namespace weg2
{
class Program
{
static void Main(string[] args)
{
// create connection & command
NpgsqlConnection con = new NpgsqlConnection("server=localhost;database=mydb;SSL=True;Encoding=UNICODE;");
NpgsqlCommand cmd = new Npgsql.NpgsqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "mydb.tbl_dt_bug_insert()"; // see `PgSQL.sql' for the source
cmd.Parameters.Add(new Npgsql.NpgsqlParameter(":p_id", NpgsqlTypes.NpgsqlDbType.Integer, 0, "id", ParameterDirection.Output, false, ((byte)(0)), ((byte)(0)), DataRowVersion.Current, null));
cmd.Parameters.Add(new Npgsql.NpgsqlParameter(":p_timestamp_store", NpgsqlTypes.NpgsqlDbType.Timestamp, 0, "timestamp_store", ParameterDirection.Output, false, ((byte)(0)), ((byte)(0)), DataRowVersion.Current, null));
// build up the result DataTable with its columns (as defined by the PgPLSQL function ouput-parameters)
DataTable tbl = new DataTable("test");
DataColumn col = null;
col = tbl.Columns.Add("id", typeof(System.Int32));
col.AllowDBNull = false;
col = tbl.Columns.Add("timestamp_store", typeof(System.DateTime));
col.AllowDBNull = true;
tbl.PrimaryKey = new DataColumn[] { tbl.Columns["id"] };
// define a single DataRow holding the PgPLSQL function return-rowset (this will be the inserted row in the database)
DataRow row = tbl.NewRow();
// open connection, execute the command, fill the data-row with the output-params of the PG stored-function
con.Open();
ExecuteNonQuery(cmd, row);
con.Close();
// just output the DataRow and wait for the user
System.Console.WriteLine("{0} | {1}", row["id"], row["timestamp_store"]);
System.Console.WriteLine("<Press Enter>"); System.Console.ReadLine();
}
/// <summary>
/// Execute the Command. Copy the output-parameters (resultset of the stored-proc) into the DataRow
/// </summary>
/// <param name="command">The command to execute</param>
/// <param name="row">The DataRow to store the resultset (feeded by the output-parameter of the command)</param>
/// <returns>The number of rows affected</returns>
public static int ExecuteNonQuery(IDbCommand command, DataRow row)
{
int ret = command.ExecuteNonQuery();
// copy the Output-Parameter into the (empty) DataRow
foreach (IDataParameter p in command.Parameters)
{
if (p.Direction == ParameterDirection.Output || p.Direction == ParameterDirection.InputOutput)
{
// !!! HERE COMES THE EXCEPTION in >= Npgsql2.0.8 with Npgsql.NpgsqlTimestamp (worked with 2.0.5)!!!
// Exception.ToString(): <<Unable to cast object of type 'NpgsqlTypes.NpgsqlTimeStamp' to type 'System.IConvertible'.Couldn't store <2010-04-27 13:20:36.133915> in timestamp_store Column. Expected type is DateTime.>>
row[p.SourceColumn] = p.Value;
}
}
return ret;
}
}
}
================ PlPgSQL Stored-Function called by the program ================
/* This function inserts a new row into the table. returns a rowset of the new "ID" and the current "TIMESTAMP" */
CREATE OR REPLACE FUNCTION tbl_dt_bug_insert(OUT p_id integer, OUT p_timestamp_store timestamp) AS $$
DECLARE
i_sql_rowcount integer;
i_timestamp timestamp;
BEGIN
i_timestamp := current_timestamp;
p_dt := i_timestamp;
p_id := max(id)+1 from tbl_dt_bug;
INSERT INTO tbl_dt_bug (id, dt) VALUES (p_id, p_dt);
GET DIAGNOSTICS i_sql_rowcount = ROW_COUNT;
RETURN /* i_sql_rowcount */;
EXCEPTION
WHEN OTHERS THEN RAISE EXCEPTION 'ERROR! SQL-Code: % SQL-Errortext: %', SQLSTATE, SQLERRM;
END;
$$ LANGUAGE plpgsql;
RE: Cast-Exception with NpgsqlTimeStamp [ reply ]
By: Josh Cooley on 2010-04-29 02:40[forum:1006012]
I'm having trouble getting the test code to run, but I know why the exception is happening. We changed the way types work. We can probably make this test work, but there's a fundamental difference between this version and earlier versions.
Earlier versions returned a System.DateTime object. We now return an NpgsqlTimeStamp. This is necessary to preserve the full range of values supported by the database. If you ask for a date time, you should get a date time, but you asked for an NpgsqlDbType.Timestamp. This particular detail is probably broken as well though, so I don't believe it would provide a work around.
Could you file a bug report on this? I propose two changes to handle this case. One is to support out parameters with the CLR type if the DbType enum is used. I'm not certain how well that will work, but I think it makes sense conceptually. The other proposed change is to support IConvertible on the provider types. This would allow conversions, but code doing casts would still fail.RE: Cast-Exception with NpgsqlTimeStamp [ reply ]
By: Bernd Pinter on 2010-04-29 06:51[forum:1006020]
To get the code running, you need at least a database (in my case it's called "relon") with a table ("tbl_dt_bug") and and a function ("tbl_dt_bug_insert") in it. The function will insert a new row into the table witha new unique ID and the current-timestamp (ct. now()):
CREATE TABLE tbl_dt_bug (
id integer not null primary key,
dt timestamp
);
CREATE OR REPLACE FUNCTION tbl_dt_bug_insert(OUT p_id integer, OUT p_timestamp_store timestamp) AS $$
DECLARE
i_sql_rowcount integer;
i_timestamp timestamp;
BEGIN
i_timestamp := current_timestamp;
p_dt := i_timestamp;
p_id := max(id)+1 from tbl_dt_bug;
INSERT INTO tbl_dt_bug (id, dt) VALUES (p_id, p_dt);
GET DIAGNOSTICS i_sql_rowcount = ROW_COUNT;
RETURN /* i_sql_rowcount */;
EXCEPTION
WHEN OTHERS THEN RAISE EXCEPTION 'ERROR! SQL-Code: % SQL-Errortext: %', SQLSTATE, SQLERRM;
END;
$$ LANGUAGE plpgsql;
===================================
The C# code itself will call this function (line 17) to insert a new row into the table. The inserted data will come back to the C# code with the two out-parameters of the postgres function.
Hope this helps to get my code up and running. If not, please let me know - at least i can send/post the complete VS08 solution to you...
Oh! And yes, i will also open a bug for this new behavior of the NpgsqlTimestamp.
bernd.RE: Cast-Exception with NpgsqlTimeStamp [ reply ]
By: Francisco Figueiredo jr. on 2010-05-11 01:20[forum:1006049]
Would it be possible that we are missing an explicit operator to DateTime to Timestamp type?
I can see an operator to TimestampTZ but not to Timestamp.
I noticed that SqlDateTime struct has an explicit operator to convert an SqlDateTime to DateTime.
Maybe internally the DataRow[] tries to cast the value to DateTime. If it is this case, the explicit operator would make it work.
What do you think?
| Does Crystal Reports need Npgsql commands? [ reply ] By: Ricardo Martin on 2010-05-07 11:07 | [forum:1006041] |
|
Hi there After working for several weeks with Npgsql, I understand why there are quite a few very good comments about how well Npgsql works! I have an issue, but not sure if really something I'm doing wrong or not. I have a Windows app in VS2008 (Net3.5) with a Crystal Report created using the wizard and connecting to PG using ODBC DSN. Eventually the report was boundto the form. Report does show real data and everythign as expected in preview mode; however, when running the app and choosing the option containing the form with CR control, it does not connect to database. It prompts for password and 'Logon Failed' error message comes up. Something strange I noticed, is that DSN name is in the server name box and the database name box is blank. My question is: do I need to use the Npgsql commands (connection, datareader, etc) to have Crystal Reports work correctly? Thanks, Ricardo |
|
RE: Does Crystal Reports need Npgsql commands? [ reply ]
By: Josh Cooley on 2010-05-09 23:59[forum:1006047]
Hi Ricardo,
Are you sure you are using Npgsql? I'd imagine an ODBC DSN would mean you're using an ODBC driver.RE: Does Crystal Reports need Npgsql commands? [ reply ]
By: Ricardo Martin on 2010-05-10 23:13[forum:1006048]
Hi John
Yes I'm using OBDC driver;however, I was not having any code to open the file and do proper selection/sorting/grouping, etc at the form level. That's why I could see real data in preview mode (where the report was in fact opening DB). I recently learned that.
So now, form does show data as expected.
Thanks for your help.
| Unicode and Ascii Issues [ reply ] By: Kengie Ho on 2010-05-05 10:27 | [forum:1006029] |
|
Hi, I am having some issues with the extract some chinese characters stored in the postgresql as an SQL_ASCII encoding. This was done due to historical issues. Now I am using the Npgsql .net 2.0.9 driver to access the data from the database. When the database is using Encoding as UTF-8, I can get my chinese characters viewing correctly. When the database is using Encoding as SQL_ASCII, the chinese characters in the database comes how as '�L�w�g'. I have tried sending the encoding to utf8, unicode and ASCII but I have always got the same results. I have even tried using the SQL statment 'SET CLIENT_ENCODING' but it still doesn't work. A little more detail info is that when I get the characters from the Unicode database and using the encoding class of .Net. My byte count for the text is 10bytes(extra byte for LF/NL i think) and if I type the actually chinese characters in the Form and using the encoding class, I am getting 9bytes. But if I am extracting the chinese characters from ASCII database, I am getting a reading of 12bytes from the encoding class. The chinese char are 林安妮. If 3bytes for one word, then it should only be only be 9bytes, which is correct if I getbytes directly from 林安妮. Somehow the ASCII database is returning some extra bytes (i think). I think it might be some issues with the driver as connecting to unicode database and getting the bytes from 林安妮 returns the same amount of bytes. Please help. Thanks. |
|
RE: Unicode and Ascii Issues [ reply ]
By: Francisco Figueiredo jr. on 2010-05-05 16:44[forum:1006030]
You will have to use Npgsql1 version as it uses ASCII encoding by default.
Npgsql2 uses UTF-8 and doesn't support ASCII encoding anymore.
After that, try importing your data to an UTF-8 encoded database and you are ready to go with Npgsql2.
I hope it helps.
RE: Unicode and Ascii Issues [ reply ]
By: Kengie Ho on 2010-05-06 02:52[forum:1006031]
It works. Thanks for your quick reply.
but now i have another issue.
In 2.0.9, i can set the driver as TestCmd.Parameters(1).NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text
How can I do this in 1.0.0 Npgsql .Net driver? Thanks.RE: Unicode and Ascii Issues [ reply ]
By: Josh Cooley on 2010-05-07 02:18[forum:1006036]
That same parameter type should be supported in the 1.0.1 version of Npgsql. RE: Unicode and Ascii Issues [ reply ]
By: Kengie Ho on 2010-05-07 02:37[forum:1006037]
nope. 1.0.1 doesn't have NpgsqlTypes.NpgsqlDbType.Array type. I have typed it in VS and the intellsense doesn't show up. VS returns an error.
Also Npgsql 1.0.1 was release on 2007-10-27 and searching through the forum. Array datatype was supported around mid 2008. So that means Array data type wasn't merged into 1.0.1.RE: Unicode and Ascii Issues [ reply ]
By: Josh Cooley on 2010-05-07 13:09[forum:1006042]
My comment was on the Text type mentioned in the previous post
TestCmd.Parameters(1).NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text
I've mentioned in another post somewhere here that we can't support array types in 1.0.1 because it requires a breaking change.
| FillSchema Npgsql 1.0.1 [ reply ] By: Kengie Ho on 2010-05-06 03:14 | [forum:1006032] |
|
Hi, It seems that the FillSchema isn't working in Npgsql 1.0.1 along with the DBType Array. Can these be roll forward in Npgsql 1.0.1? Link in regards to FillSchema: http://pgfoundry.org/forum/message.php?msg_id=1002744 Basically I need ASCII support and parameter array passing. But ASCII support is in 1.0.1 and parameter array support is in 2.0.9. These feature get merged or can npgsql support parameter array in 1.0.1? Thanks. |
|
RE: FillSchema Npgsql 1.0.1 [ reply ]
By: Kengie Ho on 2010-05-06 03:40[forum:1006033]
Sorry forgot to list the details on the bug.
You will get an index out of bound, if you use a multi table select by using the commandtext of the NpgsqlCommand object.
npgsqlcommand.commandtext = "select * form table1;select * from table3;"
This is with Npgsql 1.0.1
Workaround is currently. Pass a single table sql to the commandtext and then call the FillSchema method of NpgsqlDataAdapter. So if you have 10 tables to fill into a DataSet. You will need to set and call the FillSchema method 10 times.RE: FillSchema Npgsql 1.0.1 [ reply ]
By: Josh Cooley on 2010-05-07 02:14[forum:1006035]
We can't add array support in 1.0.1 since it requires breaking changes. Perhaps there's something that needs to be done in 2.0 tree to allow you to access your database.
| using arrays (like Int32[]) with a datatable [ reply ] By: David Jaspers on 2009-11-30 13:47 | [forum:1005598] |
|
Sample postgres database table: column a : type integer (.net Int32) column b : type integer[] (.net Int32[]) If I fill the datatable with with the dataset Fill command all is fine. I can read the data and get the column b array values. Prior to npgsql2 this was returned as an string with values like {1,3,4}. Now this is returned as Int32[]. That's Oke But Update gives an exception! sample: ds.Table[0]["b"] = new Int32[] {1,3,4}; ds.Update(); invalidcastexception: "Cannot convert type System.Int32[] to type System.IConvertible." I am migrating from the old npgsql code to npgsql2.07. Prior to npgsql2 an array was an string columntype and the values needs to be set as: ds.Table[0]["b"] = "{1,3,4}"; ds.Update(); How can I do this in npgsql2? Or is this a problem with the NPGSQL CommandBuilder not supporting arrays? |
|
RE: using arrays (like Int32[]) with a datatable [ reply ]
By: Josh Cooley on 2009-12-02 19:32[forum:1005607]
This may be a problem with the command builder or something else. Where is the InvalidCastException thrown? Can you share the call stack (or at least the top part)?
It'd also be helpful if you open a bug report with a sample reproducing the problem.RE: using arrays (like Int32[]) with a datatable [ reply ]
By: David Jaspers on 2010-04-30 08:46[forum:1006023]
Hello Josh,
Now I had the time to create a sample to reproduce the exception with npgsql 2.0.9
The problem is updating a dataset with a NpgsqlDataAdapterdapter and one of the columns is an array.
Can you take a look at the sample below?
thanks,
David
using System;
using System.Data;
using Npgsql;
namespace npgsql209test
{
class Program
{
static void Main(string[] args)
{
/*
CREATE TABLE testtable_with_array
(
id integer,
arraycol integer[]
)
WITH (OIDS=FALSE);
*/
var conn = new NpgsqlConnection("Server=192.168.0.114;Port=5432;User Id=postgres;");
conn.Open();
var da = new NpgsqlDataAdapter();
da.SelectCommand = new NpgsqlCommand("SELECT * FROM testtable_with_array", conn);
var myDS = new DataSet();
da.FillSchema(myDS, SchemaType.Source, "testtable_with_array");
var b = new NpgsqlCommandBuilder(da);
da.InsertCommand = b.GetInsertCommand();
Console.WriteLine(da.InsertCommand.Parameters[1].DbType); // Int32 ?
Console.WriteLine(da.InsertCommand.Parameters[1].NpgsqlDbType); // Integer ?
// add new row with the second column as an array
var newrow = myDS.Tables[0].NewRow();
newrow["id"] = 1;
newrow["arraycol"] = new Int32[] { 1,2,3};
myDS.Tables[0].Rows.Add(newrow);
da.Update(myDS.Tables[0]);
/* exception here:
A first chance exception of type 'System.InvalidCastException' occurred in Npgsql.dll
"Kan een object van het type System.Int32[] niet converteren naar het type System.IConvertible."
at {Int32 UpdatedRowStatusErrors(System.Data.Common.RowUpdatedEventArgs, BatchCommandInfo[], Int32)}
*
*/
conn.Close();
}
}
}
RE: using arrays (like Int32[]) with a datatable [ reply ]
By: Josh Cooley on 2010-05-03 02:10[forum:1006026]
I can reproduce this here. I can't tell if this is a limitation in the framework or something we need to do differently. .NET calls NpgsqlDataReader.GetSchemaTable() where we return the column as an int[]. A later call to NpgsqlCommandBuilder.ApplyParameterInfo passes the type in as an int. I'm still working on where the array bit is getting lost.
JoshRE: using arrays (like Int32[]) with a datatable [ reply ]
By: Josh Cooley on 2010-05-03 02:39[forum:1006027]
A few minutes after posting this I found the problem. There's a fix for it now in CVS.
The ApplyParameterInfo gets the right type (int[]), but DbType has no representation for that. I needed to convert ApplyParameterInfo to using NpgsqlDbType.
| multi-dimension array as parameter [ reply ] By: Kengie Ho on 2010-04-23 11:03 | [forum:1005980] |
|
Hi All, I am trying to call a function with several arrays are parameters. Is this possible with Npgsql .Net driver? I am getting an error of "ERROR: 42601: syntax error at or near "'''{{"ABC",1,10,"O",1,"ABC","ABC","ABC",0,""}}'''"" The generated SQL from the provider is: select * from user.save( (array'''{{"ADMIN",1,10,"O",1,"ABC","ABC","ABC",0,""}}''')::varchar[]) If i try to run the generated SQL. I will get an error in PGAdmin. As you can see the provider will generate a 'array' word in the SQL and there will also be extra quotes in the SQL. If i remove the array word and the extra quotes. The statment can run fine. Here is the VB code for value of the Parameter. TestCmd.Parameters(0).NpgsqlDbType = NpgsqlDbType.Array Or NpgsqlDbType.Varchar TestCmd.Parameters(0).Value = "'{{" & Chr(34) & "ADMIN" & Chr(34) &",1,10," & Chr(34) & "O" & Chr(34) &",1," & Chr(34) &"ABC" & Chr(34) &"," & Chr(34) & "ABC" & Chr(34) &"," & Chr(34) & "ABC" & Chr(34) &",0," & Chr(34) & "" & Chr(34) & "}}'" There are no extra single quotes in the VB code and the Chr(34) is to generate the doubles quotes. What is wrong with my code? Thanks for your help. Regards, Kengie |
|
| No return value from function [ reply ] By: Kengie Ho on 2010-04-23 11:07 | [forum:1005981] |
|
Hi All, I am getting no result value from this very simple sub in VB.Net Private Sub TestSPPostgreSQL4() Dim TestCon As New NpgsqlConnection(ConnectionString) TestCon.Open() Dim TestCmd = TestCon.CreateCommand TestCmd.CommandType = CommandType.StoredProcedure TestCmd.CommandText = "user.test" Dim RetValParam As New NpgsqlParameter TestCmd.Parameters.Add(RetValParam) NpgsqlDbType = NpgsqlDbType.Varchar TestCmd.Parameters(0).Size = 20 TestCmd.Parameters(0).Direction = ParameterDirection.ReturnValue Debug.WriteLine(TestCmd.CommandText) Dim rdr As NpgsqlDataReader = TestCmd.ExecuteReader Debug.WriteLine("Return Value is " & TestCmd.Parameters(0).Value) TestCon.Close() End Sub The function on the PostgreSQL is: CREATE OR REPLACE FUNCTION ctsuser.test() RETURNS text AS $BODY$ DECLARE ret varchar; begin return 'OK'; end; $BODY$ LANGUAGE 'plpgsql' VOLATILE; Is this a bug or is there some issues with my code? I have already followed the User's Manual instructions. By the way I am using VS 2008 and Npgsql 2.0.9 Thanks. Regards, Kengie |
|
RE: No return value from function [ reply ]
By: Francisco Figueiredo jr. on 2010-04-29 03:30[forum:1006019]
Hi!
Npgsql doesn't support ReturnValue parameter direction yet. Please, use OutputParameter and it will work ok. I tested it here.
Sorry for this problem.
| EF4 / VS 2010 compatibility [ reply ] By: hapiec peicn on 2010-03-26 10:28 | [forum:1005902] |
|
Hello, Is there any news abount EF4 compatibility? Lack of it prevents any use of npgsql with Entity Framework with visual studio 2010. |
|
| Sample of EF [ reply ] By: Fernando Siguenza on 2010-04-16 16:59 | [forum:1005949] |
|
Hello friends, please where i can see any sample of EF,how i can make de ef model?? Tanks |
|
| Postgresql (Npgsql) table consturction [ reply ] By: Mariusz Mackiewicz on 2010-04-20 18:30 | [forum:1005971] |
|
Hi, I need get table structure from Postgresql database, with Npgsql driver, in shell is command "\d table_name", and this command return "table_name" table structure. But I have problem with Npgsql: \d - command not work with npgsql (using Visual Studio 2008, C#), when I try execute "\\d table_name" command I have "ERROR: 42601 syntax error at or near "\"". Maybe you know how I can get table information? Thx ;) |
|
RE: Postgresql (Npgsql) table consturction [ reply ]
By: Bernd Pinter on 2010-04-27 13:18[forum:1006005]
Actually the \d command isn't a postgres- or a valid sql-command. Only the client "psql" can handle this. if you enter "\d mytbl" then psql creates sql for you and sends this to the backend (postgres).
Use the "-E" switch when you run psql to see what happend under the hood (~7 queries to get the \d infos from the backend) :
$ psql -E mytest_db
hope this helps,
Bernd Pinter
|
|
Older Messages |

