Sunday, October 24, 2010

Config files and XDT or Config Transforms

 

In VS 2010 there is a new feature to transform your config file for the active configuration. (for example –> Debug / Release)

All you need to do is right click on the web.config en select config transforms.

configtransforms

Now this feature is only available for Web.config files. Bedroefde emoticon

image
But i google do the search for me and i found a solution for app.config Glimlach 

image

How you do it can you find out in this blogpost written by Vishal Joshi

Now i work with this technique and i had some problems with the web.config.

Some times i get this message:

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. 
This error can be caused by a virtual directory not being configured as an application in IIS.
   

What i did to get it work:

  • Clean Project
  • Make shure that the bin folder is empty
  • Rebuild project
  • Result --> error is gonne

 

Enjoy …

Sunday, July 11, 2010

Create Journaling on a table for mysql database

If you have some tables with very sensitive data in it you would create backups.

that is 1 thing, but if somethings wrong you would like to now when and what data is changed.

 

This is a nice solution that create a copy of table that you would like to monitor.

and add a 3 triggers –> 1 for Insert, update and delete.

If some data is inserted it will be in the journaling table 2.

If Updated or deleted you wil find what is changed in that table.

I created 2 Stored procedures:

SP1 –> to create the second table(copy) with 2 extra colums.

SP2 –> to create 3 triggers

This 2 SP will write the script to a file where you would like to be.

These are my SP code:

CREATE JN_TABLE

DELIMITER $$

USE `YOUR TABLESCHEMA`$$

DROP PROCEDURE IF EXISTS `CreateJNTable`$$

CREATE PROCEDURE `CreateJNTable`(IN tabelnaamostr VARCHAR(64),IN tabelschemastr VARCHAR(64))
BEGIN
-- 1. aanmaken temp table
CREATE TEMPORARY TABLE TMPJN (ID DOUBLE AUTO_INCREMENT KEY,stringval VARCHAR(21844) NOT NULL);
-- 2. aanmaken commentaar
INSERT INTO TMPJN (stringval) VALUES (CONCAT('-- We maken een Journaling tabel aan voor tabel ',tabelnaamostr ,' in tabelschema ',tabelschemastr));
-- 3. 1e lijn stuk text toevoegen
INSERT INTO TMPJN (stringval) VALUES (CONCAT('Create table ',tabelnaamostr,'_JN('));
-- 4. We gaan de Kolom namen toevoegen + hun datatype en een comma er achter
INSERT INTO TMPJN (stringval)
SELECT CONCAT(column_name,' ', Column_type,',') AS result
FROM information_schema.columns WHERE table_name= tabelnaamostr AND TABLE_Schema = tabelschemastr ;
-- 5. We gaan de andere 2 kolomen toevoegen die nodig zijn voor de Journaling
INSERT INTO TMPJN (stringval) VALUES ('RowAction varchar(1),');
INSERT INTO TMPJN (stringval) VALUES ('Tijdstip DateTime);');
-- 6. We schrijven dit alles weg naar en file op onderstaande locatie
SELECT stringval FROM TMPJN INTO OUTFILE '\\\\\192.168.0.13\\Divers\\CreateJNTable.sql';
-- 7. Tot slot deleten we de tmp tabel
DROP TEMPORARY TABLE TMPJN;
END$$

DELIMITER ;


And



CREATE JN_TRIGGERS



 



DELIMITER $$

USE `YOUR TABLESCHEMA`$$

DROP PROCEDURE IF EXISTS `CreateJNTriggers`$$

CREATE PROCEDURE `CreateJNTriggers`(IN tabelnaamostr VARCHAR(64),IN tabelschemastr VARCHAR(64))
BEGIN
-- 1. aanmaken temp table
CREATE TEMPORARY TABLE TMPJN (ID DOUBLE AUTO_INCREMENT KEY,stringval VARCHAR(21844) NOT NULL);
-- 2. Toevoegen van vaste script lijnen
INSERT INTO TMPJN (stringval) VALUES ('DELIMITER $$');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('USE ',tabelschemastr,' $$'));
-- ************************************************************************************************************************
-- * INSERT Trigger *
-- ************************************************************************************************************************
INSERT INTO TMPJN (stringval) VALUES ('--');
INSERT INTO TMPJN (stringval) VALUES ('--');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('-- We maken een insert trigger aan voor tabel ',tabelnaamostr ,' in tabelschema ',tabelschemastr));
INSERT INTO TMPJN (stringval) VALUES (CONCAT('DROP TRIGGER IF EXISTS TR_',tabelnaamostr,'_Insert $$'));
INSERT INTO TMPJN (stringval) VALUES (CONCAT('CREATE TRIGGER TR_',tabelnaamostr,'_Insert AFTER INSERT ON ', tabelnaamostr));
INSERT INTO TMPJN (stringval) VALUES ('FOR EACH ROW BEGIN');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('INSERT INTO ',tabelnaamostr,'_JN('));
-- 3. Toevoegen van colomnamen van de Journaling tabel waar we de data gaan in stoppen
INSERT INTO TMPJN (stringval)
SELECT CONCAT(column_name,',') AS result
FROM information_schema.columns WHERE table_name = CONCAT(tabelnaamostr,'_JN') AND TABLE_Schema = tabelschemastr ;
-- 4. variable om tijdelijk de max ID bij te houden
SET @MaxID := 0;
-- 5. we stoppen de max id er in.
SELECT @MaxID := MAX(ID) FROM TMPJN;
-- 6. we gaan de laaste waarde de , er uit halen want die hoeft daar niet te staan. (anders sintax fout)
UPDATE TMPJN SET stringval = REPLACE(stringval,',',')') WHERE id = @MaxID;
-- 7. Toevoegen van vaste script lijnen
INSERT INTO TMPJN (stringval) VALUES ('VALUES(');
-- 8. Toevoegen van kolomnamen met een prefix van new. zonder de laatse 2 kolommen er bij
INSERT INTO TMPJN (stringval)
SELECT CONCAT('new.',column_name,',') AS result
FROM information_schema.columns WHERE table_name = CONCAT(tabelnaamostr,'_JN') AND TABLE_Schema = tabelschemastr AND column_name NOT IN ('RowAction','Tijdstip');
-- 9. Toevoegen van vaste script lijnen
INSERT INTO TMPJN (stringval) VALUES ('\'I\',');
INSERT INTO TMPJN (stringval) VALUES ('NOW());');
INSERT INTO TMPJN (stringval) VALUES ('END;');
INSERT INTO TMPJN (stringval) VALUES ('$$');
-- ************************************************************************************************************************
-- * UPDATE Trigger *
-- ************************************************************************************************************************
INSERT INTO TMPJN (stringval) VALUES ('--');
INSERT INTO TMPJN (stringval) VALUES ('--');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('-- We maken een Update trigger aan voor tabel ',tabelnaamostr ,' in tabelschema ',tabelschemastr));
INSERT INTO TMPJN (stringval) VALUES (CONCAT('DROP TRIGGER IF EXISTS TR_',tabelnaamostr,'_Update $$'));
INSERT INTO TMPJN (stringval) VALUES (CONCAT('CREATE TRIGGER TR_',tabelnaamostr,'_Update AFTER Update ON ', tabelnaamostr));
INSERT INTO TMPJN (stringval) VALUES ('FOR EACH ROW BEGIN');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('INSERT INTO ',tabelnaamostr,'_JN('));
INSERT INTO TMPJN (stringval)
SELECT CONCAT(column_name,',') AS result
FROM information_schema.columns WHERE table_name = CONCAT(tabelnaamostr,'_JN') AND TABLE_Schema = tabelschemastr ;
-- 4. variable om tijdelijk de max ID bij te houden
SET @MaxID := 0;
-- 5. we stoppen de max id er in.
SELECT @MaxID := MAX(ID) FROM TMPJN;
-- 6. we gaan de laaste waarde de , er uit halen want die hoeft daar niet te staan. (anders sintax fout)
UPDATE TMPJN SET stringval = REPLACE(stringval,',',')') WHERE id = @MaxID;
INSERT INTO TMPJN (stringval) VALUES ('VALUES(');
INSERT INTO TMPJN (stringval)
SELECT CONCAT('new.',column_name,',') AS result
FROM information_schema.columns WHERE table_name = CONCAT(tabelnaamostr,'_JN') AND TABLE_Schema = tabelschemastr AND column_name NOT IN ('RowAction','Tijdstip');
INSERT INTO TMPJN (stringval) VALUES ('\'U\',');
INSERT INTO TMPJN (stringval) VALUES ('NOW());');
INSERT INTO TMPJN (stringval) VALUES ('END;');
INSERT INTO TMPJN (stringval) VALUES ('$$');
-- ************************************************************************************************************************
-- * DELETE Trigger *
-- ************************************************************************************************************************
INSERT INTO TMPJN (stringval) VALUES ('--');
INSERT INTO TMPJN (stringval) VALUES ('--');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('-- We maken een Delete trigger aan voor tabel ',tabelnaamostr ,' in tabelschema ',tabelschemastr));
INSERT INTO TMPJN (stringval) VALUES (CONCAT('DROP TRIGGER IF EXISTS TR_',tabelnaamostr,'_Delete $$'));
INSERT INTO TMPJN (stringval) VALUES (CONCAT('CREATE TRIGGER TR_',tabelnaamostr,'_Delete AFTER Delete ON ', tabelnaamostr));
INSERT INTO TMPJN (stringval) VALUES ('FOR EACH ROW BEGIN');
INSERT INTO TMPJN (stringval) VALUES (CONCAT('INSERT INTO ',tabelnaamostr,'_JN('));
INSERT INTO TMPJN (stringval)
SELECT CONCAT(column_name,',') AS result
FROM information_schema.columns WHERE table_name = CONCAT(tabelnaamostr,'_JN') AND TABLE_Schema = tabelschemastr ;
-- 4. variable om tijdelijk de max ID bij te houden
SET @MaxID := 0;
-- 5. we stoppen de max id er in.
SELECT @MaxID := MAX(ID) FROM TMPJN;
-- 6. we gaan de laaste waarde de , er uit halen want die hoeft daar niet te staan. (anders sintax fout)
UPDATE TMPJN SET stringval = REPLACE(stringval,',',')') WHERE id = @MaxID;
INSERT INTO TMPJN (stringval) VALUES ('VALUES(');
INSERT INTO TMPJN (stringval)
SELECT CONCAT('OLD.',column_name,',') AS result
FROM information_schema.columns WHERE table_name = CONCAT(tabelnaamostr,'_JN') AND TABLE_Schema = tabelschemastr AND column_name NOT IN ('RowAction','Tijdstip');
INSERT INTO TMPJN (stringval) VALUES ('\'D\',');
INSERT INTO TMPJN (stringval) VALUES ('NOW());');
INSERT INTO TMPJN (stringval) VALUES ('END;');
INSERT INTO TMPJN (stringval) VALUES ('$$');
-- Vaste scriptlijn toevoegen
INSERT INTO TMPJN (stringval) VALUES ('DELIMITER ;');
-- weg schrijven van de gegevens
SELECT stringval FROM TMPJN INTO OUTFILE '\\\\\192.168.0.13\\Divers\\CreateJNTriggers.sql';
-- Tot slot deleten we de tmp tabel
DROP TEMPORARY TABLE TMPJN;
END$$

DELIMITER ;


 



After that you can call SP like this:



CALL CreateJNTable('TABLENAME','YOUR TABLESCHEMA');

CALL CreateJNTriggers('TABLENAME','YOUR TABLESCHEMA');

Tuesday, June 29, 2010

Write Mysql output to file

This is what i use to write the SQL output to a filedrive:

SELECT 1 FROM DUAL INTO OUTFILE '\\\\\192.168.0.13\\Divers\\demo.sql';

Note: you can write only once like this, otherwise you get message that the file exists. :-)

 

This example shows how to create dynamic name:

CREATE PROCEDURE export_dynamic(IN file_name CHAR(64))
BEGIN
SET @myvar = CONCAT('SELECT * INTO OUTFILE ',"'",file_name,"'",' FROM Table1') ;
PREPARE stmt1 FROM @myvar;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
END;

Tuesday, June 22, 2010

New RSS Feed URL

I use feedburner now as RSS feed URL.

Please use this RSS feed url:

http://feeds2.feedburner.com/KrisNobels


Thanks

Customize Setup wizard with your Company Logo

  1. Download Windows Installer SDK.
  2. In it you will find a Orca.msi. install it.
  3. With explorer browse to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\Deployment\VsdDialogs.
  4. There you will find a subfolder for most cultures.
  5. Go to the culture subfolder you're using.
  6. Open VsdUserInterface.wim with Orca. (or download here)
  7. In the binary table you'll find a row with name DefBannerBitmap.
  8. Double click [Binary Data] to select your own banner image file (jpg or bmp, not gif). It has to have a width of 500 pixels and a height of 70 pixels.
  9. Store the VsdUserInterface.wim.
  10. Build the setup projects again with having the BannerBitmap property refering to Default.

Sunday, January 25, 2009

Change dot "." to Comma "," with javascript

Here is the syntax to change your dot to comma.
Very handy because your hand stays in the nummeric area of your keyboard.

<html>
<head>

<script type="text/javascript">
function DotToComma(that) {
if (that.value.indexOf(".") >= 0) {
that.value
= that.value.replace(".",",");
}
}
</script>

</head>
<body>
<input type="text" name="txt" onkeyup="DotToComma(this);">
</body>
</html>


On a .ASPX page you would have something inside like this:

<asp:textbox id="TextBox1" runat="server" text="Sample Text"
onkeyup
="DotToComma(this);" />

Wednesday, July 9, 2008

Export Gridview to Excel with ASP.NET (workaround)

Today I had to create a grid in ASP.Net. But i had this problem when i created the export to Excel:
'GridView' must be placed inside a form tag with runat=server

My gridview was inside the form ???

So this is the workaround i found:

This is the normal function for the export to Excel:

Response.Clear();
Response.AddHeader(
"content-disposition", "attachment;filename=filename.xls");
Response.Charset
= "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType
= "application/vnd.xls";
System.IO.StringWriter stringWrite
= new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite
= new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

/* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */
public override void VerifyRenderingInServerForm(Control control){}


Just insert this inside your code behind:



More info you can find here @ microsoft (Microsoft has accepted it as bug)

Saturday, March 22, 2008

List of software to install on Clean OS

List of default items to Install:

List of Software you need as .NET developer:

List of software you need as web developer:

List of software that is handy:

  • Virtual PC (Run other OS in Virtual mode)
  • Windows Live Writer (Tool for writing blogposts)
  • MP3TAG Edit your Metadata of common audio formats. Add Pciture, full song info, ...

List working with Silverlight:

Handy Stuff you would like:

If you have a handy ore better tool please let me now. :-)

Kris Nobels

-- = Last updated 19-03-2009 = --

Tuesday, February 12, 2008

Handy stuff when you work with MS SQL Database

GENERAL REMARK:
SQL SERVER IS IN MOST CASES INSTALLED CASE INSENSITIVE
IF INSTALLED CASE SENSITIVE USE UCASE('YOUR_VALUE')


The select for finding all Stored (P) Procedures, (TR) Triggers, (V) Views, (FN) scalar functions, (TF) Table valued Functions, (IF) inline table valued functions, (RF) replication filter procedures and (R) rules where you use some specific text:
SELECT *
FROM sys.sql_modules m INNER JOIN
sys.objects o
ON m.object_id = o.object_id
WHERE definition LIKE '%YOUR_VALUE%';



Statement that returns all tables and views where column is used:



SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'YOUR_VALUE';




Select statement for finding the indexes use on some Column name:



SELECT *
from sys.index_columns ic INNER JOIN
sys.columns o
ON ic.object_id = o.object_id AND ic.column_id = o.column_id INNER JOIN
sys.tables t
ON ic.object_id = t.object_id INNER JOIN
sys.indexes i
ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE o.name = 'YOUR_VALUE'



Select statement for finding constraints use on some column name:

SELECT *
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE COLUMN_NAME = 'YOUR_VALUE';



Monday, February 11, 2008

Handy stuff when you work with oracle Database

When a database is so big and you do not now where to start, here are some helpfull selectstatements.

Let oracle search it for you.

Here are some usefull Selects:

  • The select for finding all Stored Procedures where you use some specific text
    select * from all_source where Upper(text) like Upper('%YOUR_VALUE_TO_SEARCH%');

  • Select statement where you use the column name in a table
    select * from all_tab_columns where column_name = Upper('YOUR_VALUE_TO_SEARCH');

  • Selectstatement for finding the indexes use on some Column name
    select * from all_ind_columns where column_name = Upper('YOUR_VALUE');

  • Select statement for finding constraints use on some column name
    select * from all_cons_columns where column_name = Upper('YOUR_VALUE');

Performace Tips:

  • Find the record count , the fastest way
    Select Count(0) from TABLENAME;

  • Left join is slower against Inner join.

Reason:
When you use * it uses a varchar, when you use a number is it faster. there is no cast form varchar to Integer

  • Update TableName set Columname = 1 where CMD_ID in (Select CMD_ID from TableName)
    the updatestatement above works but slow, use this instead:
    Update TableName1 set Columname = 1
    where exists (
    Select 1 from TableName2
    where TableName1.CMDID = TableName2.CMDID
    )

  • Write a select statement that works faster
    Select id, name, firstname, function
    from functionlist FL
    inner join person P on P.personid = FL.id
    inner join functions F on F.functionid = FL.idfunction

  • If table contains something like
    Select 1 from TableName where rownum < 2
    The database stops searching when it finds the first item.

Oracle Version

  • select * from v$version
  • select * from product_component_version;