Monday, January 15, 2007

Sunday, January 14, 2007

some weird postgresql server setup

postgresql 8.2 works in odbc 8.1.2.0 -- psqlodbc-08_01_0200.zip

postgresql 8.2.1 works in lower version (8.1.1.1) -- psqlodbc-08_01_0101.zip

Wednesday, December 20, 2006

Bleeping Computer - rundl132.exe - File Information

Bleeping Computer - rundl132.exe - File Information: "Name: [not used]
Filename: rundl132.exe
Command: C:\Windows\rundl132.exe
Description: Added by the W32/Looked-A EXE virus.
File Location: %WinDir%
Startup Type: This program uses either the Load= entry in the win.ini or the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Load to load the program."

Slashdot | Google Deprecates SOAP API

Slashdot | Google Deprecates SOAP API: " {look;gawk;find;sed;talk;grep;touch;finger;find;fl ex;unzip;head;tail; mount;workbone;fsck;yes;gasp;fsck;more;yes;yes;eje ct;umount;makeclean; zip;split;done;exit:xargs!!;)}


So is that why nerds are getting acused of rape? (Not checking return codes...)
The semicolons should be double ampersands, so that execution will stop if a command fails."

O'Reilly Radar > Google Deprecates Their SOAP Search API

O'Reilly Radar > Google Deprecates Their SOAP Search API: "Update #2: Tim writes: On the other hand, SOAP has always been a political football shaped by big companies who were seeking to use it to turn web services back into a controllable software stack. (I remember the first web services summit we did, where a Microsoft developer who I won't name admitted that SOAP was made so complex partly because 'we want our tools to read it, not people.') And it could be that innovation in web services is what we need. However, backwards compatibility is worth preserving, at least for a notice period so people can make an orderly transition. However, it sounds like they are doing that."

Wednesday, December 13, 2006

How To Change The Screen Resolution in C#: "


How To Change The Screen Resolution in C#
By Joshy George

Introduction

This is a sample program that will demonstrate how to change resolution at runtime.

All programmers are facing common problem is how to change screen Resolution dynamically. In .Net 2005 it's very easy to change the screen resolution. Here I will explain you how can we get the Screen resolution and how we will change the resolution at dynamically and while unloading the page it will come as it was before. In dot net we can access the values of user's screen resolution through the Resolution class. It also affects all running (and minimized) programs.

Important Functions

No Functions

Page_Load

Screen Srn = Screen.PrimaryScreen;
tempHeight = Srn.Bounds.Width;
tempWidth = Srn.Bounds.Height;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "");
//if you want Automatically Change res.at page load. please uncomment this code.

if (tempHeight == 600)//if the system is 800*600 Res.then change to
{
FixHeight = 768;
FixWidth = 1024;
Resolution.CResolution ChangeRes = new Resolution.CResolution(FixHeight, FixWidth);
}
Change Resoultion
  switch (cboRes.SelectedValue.ToString())
{
case "800*600":
FixHeight = 800;
FixWidth = 600;
Resolution.CResolution ChangeRes600 = new Resolution.CResolution(FixHeight, FixWidth);
break;

case "1024*768":
FixHeight = 1024;
FixWidth = 768;
Resolution.CResolution ChangeRes768 = new Resolution.CResolution(FixHeight, FixWidth);
break;
case "1280*1024":
FixHeight = 1280;
FixWidth = 1024;
Resolution.CResolution ChangeRes1024 = new Resolution.CResolution(FixHeight, FixWidth);
break;

}

Thursday, December 07, 2006

Varlena, LLC | PostgreSQL General Bits Newsletter: "Turn off triggers for bulk load
[GENERAL] Turning off triggers ? 25-Nov-02

Another issue with bulk loading is triggers firing with each row inserted. If you are sure your data is trustworthy and already meets your referential integrity requirements, you can turn off triggers for the bulk load and turn them back on immediately afterward. You should not use this option when your data is not completely clean.

The reltriggers field in the pg_class table contains the number of triggers active for each table. It can be set to 0 the disable the triggers, but will need to be reset to the proper number of triggers to have them re-enabled.

UPDATE 'pg_class' SET 'reltriggers' = 0 WHERE 'relname' = 'tablename';

UPDATE pg_class SET reltriggers = (
SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid)
WHERE relname = 'table name';

Contributors: Glen Eustace geustace at godzone.net.nz, Stephan Szabo"

Wednesday, December 06, 2006

should this blog still be called .NET Webservices?

for some program's performance reason, i will recode dataset retuning webservices to .NET Remoting.


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

the proxy(stub) code for middletier



using System;
using System.Data;

namespace SyerDll
{
public abstract class RemoteObjectDef : MarshalByRefObject
{
public abstract string Test();

public abstract DataSet ReturnHeader();
}
}

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


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

sample Client Code:

using System;
using System.Data;

using SyerDll;


class Mate
{


public static void Main()
{

Console.WriteLine("Creating Remote Object.");

string url = "tcp://192.168.10.254:8076/RemoteObjectXXX";
/*RemoteObjectDef ro = (SyerDll.RemoteObjectDef)Activator.GetObject(
typeof(SyerDll.RemoteObjectDef), url );*/

RemoteObjectDef ro = (SyerDll.RemoteObjectDef)Activator.GetObject(
typeof(SyerDll.RemoteObjectDef), url );


DataSet rs = ro.ReturnHeader();


for(int i = 0; i < rs.Tables[0].Rows.Count; i++)
Console.WriteLine(rs.Tables[0].Rows[i]["Lastname"].ToString());

Console.WriteLine("Remote Object says " + ro.Test() );
}

}

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

sample Server Code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SyerDll;
using System.Data;


using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;


namespace TheServer
{
public class RemoteObject : SyerDll.RemoteObjectDef
{
public override string Dancer()
{
return "UMD";
// throw new Exception("The method or operation is not implemented.");
}

public override DataSet ReturnHeader()
{
DataSet ds = new DataSet();
DataTable t = new DataTable();

t.Columns.Add("Lastname", typeof(string));

t.Rows.Add("Lennon");
t.Rows.Add("McCartney");
t.Rows.Add("Harrison");
t.Rows.Add("Starr");

// ds.Tables[0].Rows[0][0]
ds.Tables.Add(t);



return ds;

//throw new Exception("The method or operation is not implemented.");
}

public override string Test()
{
return "Hello mike" + DateTime.Now.ToString();
// throw new Exception("The method or operation is not implemented.");


}

static void Main(string[] args)
{


// Set up the configuration parameters through a dictionary
IDictionary properties = new Hashtable();
properties.Add("port", 8076);
properties.Add("secure", false);
// properties.Add("impersonate", false);

// Create an instance of a channel
TcpServerChannel serverChannel =
new TcpServerChannel(properties, null);
ChannelServices.RegisterChannel(serverChannel,false);
// ChannelServices.RegisterChannel(new TcpChannel(8076));
Type RemoteType = Type.GetType("TheServer.RemoteObject");

// RemotingConfiguration.RegisterWellKnownServiceType(RemoteType, "RemoteObjectXXX", WellKnownObjectMode.SingleCall);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(TheServer.RemoteObject), "RemoteObjectXXX", WellKnownObjectMode.SingleCall);

//while(true)
Console.WriteLine("Michael Buen");
Console.ReadLine();
}
}
}

Saturday, December 02, 2006

restore postgresql database

raw backup and restore of postgresql, ala-mssql's sp_attach_db.


copy the whole c:\program files\postgresql

:D


then copy to other computer, set the necessary permission(note: NTFS) , like the windows username: postgres-acct. note that postgres-su (superuser), has no bearing in windows usernames, you must not look for this user

Friday, December 01, 2006

FAQ: Technical - Mono: "What is a 100% .NET application?

A '100% .NET application' is one that only uses the APIs defined under the System namespace and does not use P/Invoke. These applications would in theory run unmodified on Windows, Linux, HP-UX, Solaris, MacOS X and others. Note that this requirement also holds for all assemblies used by the application. If one of them is Windows-specific, then the entire program is not a 100% .NET application. Furthermore, a 100% .NET application must not contain non-standard data streams in the assembly. For example, Visual Studio .NET will insert a #- stream into assemblies built under the 'Debug' target. This stream contains debugging information for use by Visual Studio .NET; however, this stream can not be interpreted by Mono (unless you're willing to donate support). Thus, it is recommended that all Visual Studio .NET-compiled code be compiled under the Release target before it is executed under Mono."

Howto Backup PostgreSQL Databases | nixCraft

Howto Backup PostgreSQL Databases

Posted by LinuxTitli in Linux, Howto, UNIX, Data recovery, Backup

I rarely work on PostgreSQL database. Recently I had received a request to backup PostgreSQL databases as one of our client want to reformat server. PostgreSQL is a one of the robust, open source database server. Like MySQL database server, it also provides utilities for creating backup.

Login as a pgsql user$ su - pgsqlGet list of database(s) to backup$ psql -lBackup database using pg_dump command. pg_dump is a utility for backing up a PostgreSQL database. It dumps only one database at a time. General syntax:
pg_dump databasename > outputfile

To dump a payroll database:
$ pg_dump payroll > payroll.dump.outTo restore a payroll database:
$ psql -d payroll -f payroll.dump.outOR$ createdb payroll
$ psql payroll
However, in real life you need to compress database:$ pg_dump payroll | gzip -c > payroll.dump.out.gzTo restore database use the following command:$ gunzip payroll.dump.out.gz
$ psql -d payroll -f payroll.dump.out
Here is a shell script for same task:#!/bin/bash
DIR=/backup/psql
[ ! $DIR ] && mkdir -p $DIR || :
LIST=$(psql -l | awk '{ print $1}' | grep -vE '^-|^List|^Name|template[0|1]')
for d in $LIST
do
pg_dump $d | gzip -c > $DIR/$d.out.gz
done
Another option is use to pg_dumpall command. As a name suggest it dumps (backs up) each database, and preserves cluster-wide data such as users and groups. You can use it as follows:$ pg_dumpall > all.dbs.outOR$ pg_dumpall | gzip -c > all.dbs.out.gzTo restore backup use the following command:
$ psql -f all.dbs.out postgresReferences:

Wednesday, November 29, 2006

No buffer space available Fix (affected program: PostgreSQL for windows)

No buffer space available Fix: "If you are running Windows NT/2000/XP follow these steps: First step is to launch the registry editor. To do this go to Start, Run and type regedit. In the left pane navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters once there, you must create the entry TcpNumConnections. To do this, right click in the right pane and choose new from the menu and select DWORD Value. Give it the name TcpNumConnections. Then right click it and select modify and enter a value of 200.

Restart your computer, if all goes well then you fixed the problem, if not, revert the changes by restoring the registry. (You may have to reboot to safe mode to do this)."

Tuesday, November 28, 2006

Crystal Reports - Database Login dialog when using datasets - .NET VB:

Re: Crystal Reports - Database Login dialog when using datasets
I found out something... You need to check the properties in the 'Datasource Location' screen on your form/report (in the designer). In more detail... right click on 'Database Fields' and choose 'Set Datasource Location'... then verify or 'Replace' the datatable (or dataset) you have with the new one.

This is a HUGE ISSUE if you were using a custom namespace and, from the previous post/replys had to remove the namespace... it DOES NOT get removed from the datasource. Now, using this 'Set Datasource Location' helps with not having to redesign or drop the fields (or new fields) back on the form... it simply updates it for you.

This got rid of the 'Database Login Dialog' from popping up!

i hope this helps someone
ward0093

boolean queries technique for monthly summary report

The other night at edmug Richard Campbell presented some good SQL Querying Tips & Techniques. A lot of them were about sql 2005 which was nice to see (espeically using Common Table Expressions which are quite handy in the case of recursion).

The coolest thing I found was in regards to a cross tab query. The example used was to get sales amount by month for each employee. As you can see in the following example this is done with a lot of subqueries that builds a hideous execution plan.

SELECT Salespeople.Salesperson, SUM(S1.Quantity*S1.Price) AS Total,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=1 AND S2.Sales_ID = S1.Sales_ID) AS Jan,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=2 AND S2.Sales_ID = S1.Sales_ID) AS Feb,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=3 AND S2.Sales_ID = S1.Sales_ID) AS Mar,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=4 AND S2.Sales_ID = S1.Sales_ID) AS Apr,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=5 AND S2.Sales_ID = S1.Sales_ID) AS May,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=6 AND S2.Sales_ID = S1.Sales_ID) AS Jun,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=7 AND S2.Sales_ID = S1.Sales_ID) AS Jul,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=8 AND S2.Sales_ID = S1.Sales_ID) AS Aug,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=9 AND S2.Sales_ID = S1.Sales_ID) AS Sep,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=10 AND S2.Sales_ID = S1.Sales_ID) AS Oct,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=11 AND S2.Sales_ID = S1.Sales_ID) AS Nov,
(SELECT SUM(S2.Quantity*S2.Price) FROM Sales AS S2 WHERE
DatePart(mm,S2.Invoice_Date)=12 AND S2.Sales_ID = S1.Sales_ID) AS Dec
FROM Sales AS S1 INNER JOIN Salespeople ON S1.Sales_ID = Salespeople.Sales_ID
GROUP BY Salespeople.Salesperson, S1.Sales_ID;

A Russiam mathemetician by the name of Rozenshtein has a great query (I beleive it was called a boolean query)

SELECT Salespeople.Salesperson, SUM(Sales.Quantity*Sales.Price) AS Total,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-1)))) AS Jan,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-2)))) AS Feb,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-3)))) AS Mar,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-4)))) AS Apr,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-5)))) AS May,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-6)))) AS Jun,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-7)))) AS Jul,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-8)))) AS Aug,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-9)))) AS Sep,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-10)))) AS Oct,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-11)))) AS Nov,
SUM(Sales.Quantity*Sales.Price*(1-ABS(SIGN(DatePart(mm,Sales.Invoice_Date)-12)))) AS Dec
FROM Sales INNER JOIN Salespeople ON Sales.Sales_ID = Salespeople.Sales_ID
GROUP BY Salespeople.Salesperson;


Breaking this down we take the numeric month out of the Invoice date with the DatePart(mm, Sales.Invoice_date) section. Next the value is run through the SIGN method. SIGN converts a number to a +1 if greater than 0, 0 if the value is 0, or -1 if the number is less than 0. Then convert the number to a positive using ABS (absolute value). Then subtract the value from 1 so now we have a boolean 0 or -1 for the current row. Then multiply the data (in this case the queantiy * price) by the value we have been calculated. So if the row is in the current month it will be multiplied by -1, otherwise by 0 (and hence equal 0 so it will not be included in the sum).

Here is a table showing the value at each step


Subtraction SIGN ABS Subtraction
Jan 2 1 1 0
Feb 1 1 1 0
Mar 0 0 0 1
Apr -1 -1 1 0
May -2 -1 1 0
Jun -3 -1 1 0

If you look at the execution plan for this method you will see it is drastically more efficient which really helps with large amounts of data. This technique does not have to be used for dates. A good example Richard Campbell showed was using CharIndex to find a name (as it will return -1 if not found, 0 if an exact match, or greater than 0 if contained within the word). Basically anything you can turn into a numeric to say you have matched something vs. not matched then this technique should be applicable.

connection string for postgresql blob and insufficient base table information error

"Driver={PostgreSQL ANSI};uid=postgres-su;pwd=whiteboard-su;Database=thephoto;Server=localhost;ByteaAsLongVarBinary=1;ReadOnly=0;Parse=1"

Monday, November 27, 2006

mono exe

After using Mono for a while, you'll probably get sick of running programs using the mono command. Fear not though, since there's a little-known Linux feature ready to rescue you: miscellaneous binary format support. This lets you specify applications to run different types of files, much like file associations in Nautilus or Konqueror. Try these commands:

modprobe binfmt_misc
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register

If everything goes well, running Mono EXE files should work transparently. Put these commands into an appropriate startup script and you should be set. If you're running Debian though, you shouldn't have to bother - the Mono packages are built to set up miscellaneous binary support automatically

Sunday, November 26, 2006

solution to no buffer space available postgresql (postgres is port 5432)

When you try to connect from TCP ports greater than 5000 you receive the error 'WSAENOBUFS (10055)': "RESOLUTION
Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall your operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.
The default maximum number of ephemeral TCP ports is 5000 in the products that are included in the 'Applies to' section. A new parameter has been added in these products. To increase the maximum number of ephemeral ports, follow these steps:
1. Start Registry Editor.
2. Locate the following subkey in the registry, and then click Parameters:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
3. On the Edit menu, click New, and then add the following registry entry:
Value Name: MaxUserPort
Value Type: DWORD
Value data: 65534
Valid Range: 5000-65534 (decimal)
Default: 0x1388 (5000 decimal)
Description: This parameter controls the maximum port number that is used when a program requests any available user port from the system. Typically , ephemeral (short-lived) ports are allocated between the values of 1024 and 5000 inclusive.
4. Quit Registry Editor."

Saturday, November 25, 2006

how to save images in postgresql database

Set ImgXCtrl1.Picture = LoadPicture("c:\windows\wallpaperbrucelee14.jpg")

Set c = New ADODB.Connection
c.CursorLocation = adUseClient
c.Open "Driver={PostgreSQL ANSI};uid=postgres-su;pwd=whiteboard-su;Server=localhost;Database=test;ByteaAsLongVarBinary=1"





Dim jpg As New MycJpg ' core code comes from intel jpeg library

Set r = New ADODB.Recordset
r.CursorLocation = adUseClient
r.Open "SELECT i, imx FROM images where 1 = 0", c, adOpenStatic, adLockOptimistic


Dim b() As Byte
b = jpg.PicToJpba(ImgXCtrl1.Picture)


r.AddNew
r.Fields("i").Value = 3
r.Fields("imx").Value = b
r.Update