Search This Blog

Monday, February 22, 2010

Added Microsoft Access as linked server SQL Server

SQL Server > Linked Server > Add

sp_addlinkedserver

Creates a linked server. A linked server allows for access to distributed, heterogeneous queries against OLE DB data sources

sp_addlinkedsrvlogin

Creates or updates a mapping between a login on the local instance of SQL Server and a security account on a remote server.

Example: Add Microsoft Access as linked server SQL Server
 
USE master
GO
-- To use named parameters:
EXEC sp_addlinkedserver
@server = 'ACCES',
@provider = 'Microsoft.Jet.OLEDB.4.0',
@srvproduct = 'OLE DB Provider for Jet',
@datasrc = 'D:\data\DB1.mdb'
GO

-- set password
EXEC sp_addlinkedsrvlogin 'ACCES', false, 'sa', 'Admin', NULL





Thursday, February 4, 2010

First, last day of the month Oracle

Oracle > Date & Time > First day and last day of the month Oracle


SELECT (trunc(sysdate, 'mm')) first_day FROM dual;
SELECT last_day(trunc(sysdate)) last_date FROM dual;
--result
FIRST_DAY
-----------
12/1/2010

LAST_DATE
-----------
12/31/2010

Tuesday, January 26, 2010

Duplicate rows SQL Server

SQL Server > Scripts > Duplicate rows SQL Server

Here is a script to find number of duplicate rows in SQL Server

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
DROP TABLE tbl1;
GO
 

CREATE TABLE tbl1
(
       id     int ,
       name   varchar(50)
);
GO
 
INSERT INTO tbl1 values  (1,'john'), (2,'dan') , (1,'john')
GO
 
SELECT
  id,
  count(name) 'Number of duplicate rows'
FROM
  tbl1
GROUP BY
  id
HAVING
  count(name) > 1
GO

Result:
id Number of duplicate rows
1 2


 






Wednesday, January 20, 2010

send fax C#


Send fax C# using using FAXCOMLib;

public void SendFax(string DocumentName, string FileName, string RecipientName, string FaxNumber)
 {
         FAXCOMLib.FaxServer faxServer = new FAXCOMLib.FaxServerClass();
         faxServer.Connect(Environment.MachineName);
         FAXCOMLib.FaxDoc faxDoc = (FAXCOMLib.FaxDoc)faxServer.CreateDocument(FileName);
         faxDoc.RecipientName = RecipientName;
         faxDoc.FaxNumber = FaxNumber;
         faxDoc.Tsid = "Fax";
         faxDoc.DisplayName = DocumentName;
         int Response = faxDoc.Send();
          faxServer.Disconnect();
}
 

 

Tuesday, January 19, 2010

Get windows temporary path c#

C# > Files > GetTempPath

GetTempPath retrieves the path of the directory designated for temporary files.

Order to check for the existence of environment variables:
  1. TMP environment variable.
  2. TEMP environment variable.
  3. USERPROFILE environment variable.
  4. Windows directory.
Example:

String tempPath = System.IO.Path.GetTempPath();










FRM-40654: Record has been updated by another user

Oracle > dml_data_target_name

FRM-40654: Record has been updated by another user

The case that I had was i changed the query of 1 database block dynamically use set_block_property(’BLOCK1′,Query_Data_Source_Name,’TABLE_X’). This BLOCK1 previously assign to TABLE_A. TABLE_X and TABLE_A has same fields structure.


FRM-40654

As summary, my form blocks condition were like this :
BLOCK1 = TABLE_A

Solution:

use set_block_property on pre_query trigger to change the query_data_source_name to TABLE_X.

Everything looks fine when i load the form, but when i tried to change the field value, it gave me this form error FRM-40654. I search around in Google and only can found several peoples face the same frm-40654 but in different situation.


set_block_property(’BLOCK1′,dml_data_target_name,’TABLE_X’)








Friday, January 15, 2010

Rename Microsoft Access Table

VB 6 > DAO > Rename table

(Used DAO 3.6 as reference.)

Public Sub rentbl()
  Dim dbSS As Database
  Dim strDbName As String
  strDbName = "c:\temp\test.mdb"
  Set dbSS = OpenDatabase(strDbName)
  dbSS.CreateTableDef
  dbSS.TableDefs("R2").Name = "Org_R2"
  dbSS.Close
  Set dbSS = Nothing
End Sub