Monday, August 6, 2012

VB6 Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection

If you are getting the next error on your VB6 applications when trying to run selects:


Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection


Looks like the problem is in the ODBC connection. Be sure  you have selected the check boxes:
Use ANSI quoted identifiers
Use ANSI nulls, paddings and warnings


Friday, August 3, 2012

VB6 No creatable public component detected

If you get the error "No creatable public component detected" when trying to compile a new VB application like the one below, you need to change the Instancing value because it is private.


Just change the instancing to Multiuse or GlobalMultiuse:


Tuesday, July 17, 2012

Controls dynamically added in ASP.NET are lost after a postback

If you are loosing your controls added dynamically to a web page after a full or partial postback, is because you are not creating them in the Page.Init.

According to the ASP.NET Page Life Cycle, PostData (all values inputed on the client side) is applied between the Page.Init and Page.Load, so, if you add a control in the Page.Init, they will not lose their state and you don't have to recreate them.



        protected void Page_Init()
        {

        Control ct = ParseControl("");

        Page.Controls.add(ct);

        }


TemplateControl.ParseControl the easy way to add controls

The TemplateControl.ParseControl() is a powerfull tool to convert a string into a control, if you want to add controls to your web page this object will help you avoid a lot of coding.





// Create the label control
Control ct = ParseControl("");

// Add the control to the page
Page.Controls.Add(ct);

//
// Create a string with a table and a label
string tbl = "b
Text
"; // Create the control Control ctrl = Page.ParseControl(tbl); // Add it to the page PageControls.Add(ctrl);

Tuesday, June 26, 2012

-- How to get all field names in a table using sql query

You can get the information of the columns in a table programatically using a query.


  -- This query will return all the information of the table named MyTable
  SELECT * 
  FROM   information_schema.columns
  WHERE  table_name = 'MyTable'


Friday, May 25, 2012

System.Configuration.ConfigurationManager not found

If you added the reference in your code already:


using System.Configuration;

but still the System.Configuration.ConfigurationManager.ConnectionStrings is not found in your code, looks like you need to manually add a reference to the System.Configuration.dll file.

To add the System.Configuration follow the next simple steps:

  1. Righ click on the references folder
  2. Select Add a reference
  3. Select Assemblies >> Framework
  4. Search for the System.Configuration and select it
  5. Click the Add button

Tuesday, May 22, 2012

-- Setting the default format with Paste Special in Word 2007

It is possible to set the defualt formatting in the "Paste Special" command to Unformatted Text, most of the time we want to keep the that Word or Excel documents to retain the current format and not from which they were copied.


To chance your default Paste for Word 2007:
  1. Click the Office Button
  2. Click Word Options
  3. Click Advanced, and go to the Cut, Copy, Paste section
  4. Set the options to "Keep text only"


Monday, April 9, 2012

Split string with more than one char as delimiter


To split an string with a delimiter with more than one character like;
This is my list \r\nOranges \r\nApples \r\nGrapes
you can use:



//

string[] sArray = System.Text.RegularExpressions.Regex.Split(value, "\r\n");

//


Another option that works faster is:


//

char[] delimiters = new char[] { '\r', '\n' };
string[] sArray = MyString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

//

Thursday, April 5, 2012

Search text in SQL store procedures


Here we show a couple examples that help to search for one specific store procedure, or table in the store procedure.



--
-- Specify the database to be used
 USE my_db

-- Show all the store procedures 
 SELECT *
 FROM sys.procedures

-- Look in all the store procedures the ones that reference the users table
 SELECT *
 FROM sys.procedures
 WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%users%'


-- Look for all the store procedures the ones using the user_id column
 SELECT *
 FROM sys.procedures
 WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%user_id%'

-- In older versions of SQL
    SELECT *
    FROM INFORMATION_SCHEMA.ROUTINES 
    WHERE ROUTINE_DEFINITION LIKE '%TEXT%' AND 
   ROUTINE_TYPE='PROCEDURE'

Thursday, March 8, 2012

Unable to Attach the database after deleting the log file


If you are unable to Attach the database after deleting the log file and you get the error message:
The physical file ...... may be incorrect
This error happens when a database was not shutdown cleanly we are unable to attach it property with the command:

--
--
EXEC sp_attach_single_file_db @dbname = 'MyDB', 
    @physname = N'C:\Program FilesSQL Server\\Data\MyDB';
--
--


To fix this problem we have to:
-Create a database of equal size to the one you're trying to attach
-Shutdown the server
-Swap in the old mdf file
-Bring up the server and let the database attempt to be recovered and then go into suspect mode
-Put the database into emergency mode with ALTER DATABASE
     --
     --
     EXEC sp_resetstatus 'MyDB';
     ALTER DATABASE MyDBSET EMERGENCY
     --
     --

          If you can not do it, in the sysdatabase look for your db and set the stats field to 32768
          After the db is in emergency mode you can read from it using enterprise manager SQL 2005


-Bringup the database in emergency mode, you should be able to read from it
          If the DB is corrupted or if it is in "Suspect" mode run the command to rebuild:
                DBCC CHECKDB (dbname, REPAIR_ALLOW_DATA_LOSS)
     --
     --
     DBCC checkdb('yourDBname')
     ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE
     DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
     ALTER DATABASE yourDBname SET MULTI_USER
     --
     --

-Create a new database and extract the data from the database that is in emergency mode

The database should be ready to be used, there is a probability you lost some information or the tables lost the default values and identities.
This is a great article with all the steps:
http://www.gerixsoft.com/blog/mssql/recovering-mssql-suspect-mode-emergency-mode-error-1813




Friday, February 24, 2012

JQuery check all checkboxes

This is the easiest way to check and uncheck checkboxes in a form.
   
//
// Include a reference to the Jquery library