Tag Archives: sql

The installer has encountered an unexpected error installing this package.This may indicate a problem with this package.The error code is 29506 – SQL Server Management Studio

Hey everyone,

I ran into the following error while trying to install Sql Server Management Studio on Windows 8:

The installer has encountered an unexpected error installing this package.This may indicate a problem with this package.The error code is 29506

To fix it, all you need to do is run the exe with administrative privileges.

View Generated SQL in Entity Framework (EF)

Hey everyone,

Just a quick post on how to view the generated sql in entity framework. To start with, just add the following line to your db context constructor:

public class TestDbContext : DbContext
    {
        public TestDbContext() : base("name=TestDbContext")
        {
            this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); //This line
        }
        ...

With this line added, you should now be able to see all of your generated sql in the output window.

SELECT TOP (1) 
    [Project1].[VidId] AS [VidId], 
    [Project1].[CreatedAt] AS [CreatedAt], 
    [Project1].[CHECK] AS [CHECK], 
    [Project1].[SourceCheck] AS [SourceCheck]
    FROM ( SELECT 
        [Extent1].[VidId] AS [VidId], 
        [Extent1].[CreatedAt] AS [CreatedAt], 
        [Extent1].[CHECK] AS [CHECK], 
        [Extent1].[SourceCheck] AS [SourceCheck]
        FROM [dbo].[Vids] AS [Extent1]
        WHERE [Extent1].[VidId] < @p__linq__0
    )  AS [Project1]
    ORDER BY [Project1].[VidId] DESC
 
-- p__linq__0: '535' (Type = Int32)
-- Executing at 28/06/2014 5:00:16 PM +10:00
-- Completed in 0 ms with result: SqlDataReader

If you’re not using EF6, there were a few other options where I came across this solution: http://stackoverflow.com/a/20751723/522859

ORA-28000: the account is locked – PeopleSoft

Hey everyone,

Just a small PeopleSoft issue I ran into while running an SQR:

(SQR 5528) ORACLE OCISessionBegin(RDBMS) error 28000 in cursor 0:
   ORA-28000: the account is locked
(SQR 4701) Cannot logon to the database.

SQR for PeopleSoft: Program Aborting.

For some reason the sysadm account had been locked, thankfully there’s a fairly easy fix:

1
ALTER USER sysadm ACCOUNT UNLOCK;

If you don’t have access you may need to get a DBA to run it.

View Last Query Executed – Oracle

Hey all,

Just a quick post on how to view recent queries run into an Oracle database:

 
SELECT sql_text, sql_fulltext
  FROM v$sql
ORDER BY last_load_time DESC

Cheers

Oracle – Number of Weekdays Between Two Dates

Hey everyone,

Just a quick post on how to select the number of weekdays between two dates:

SELECT temp_tbl.days
--SELECT COUNT(temp_tbl.days)
FROM (          
        SELECT (TRUNC(TO_DATE ('01/08/2012', 'DD/MM/YYYY'), 'dd') + LEVEL - 1) days
        FROM DUAL
        CONNECT BY LEVEL <= TO_CHAR(TO_DATE('10/08/2012', 'DD/MM/YYYY') - TO_DATE('01/08/2012', 'DD/MM/YYYY'))
     ) temp_tbl
WHERE TO_CHAR(temp_tbl.days, 'D') >= 2
      AND TO_CHAR(temp_tbl.days, 'D') <= 6

Sending Email – PL/SQL

A quick post on how to send an email with PL/SQL.

There’s a LOT of documentation available at the following link:
http://www.orafaq.com/wiki/Send_mail_from_PL/SQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
PROCEDURE EMAIL_ERROR_REPORT IS
 
       /* Create vars */
       v_From        VARCHAR2 (80) := 'test@test.com';
       v_Recipient   VARCHAR2 (80) := 'me@me.com';--REPORT_RECEIVER;
       v_Subject     VARCHAR2 (80) := 'test subject';
       v_Mail_Host   VARCHAR2 (30) := 'smtp.test.com';
       v_Mail_Conn   UTL_SMTP.Connection;
       crlf          VARCHAR2 (2) := CHR (13) || CHR (10);
    BEGIN
 
       /* Define connection */
       v_Mail_Conn := UTL_SMTP.Open_Connection (v_Mail_Host, 25);
       UTL_SMTP.Helo (v_Mail_Conn, v_Mail_Host);
       UTL_SMTP.Mail (v_Mail_Conn, v_From);
       UTL_SMTP.Rcpt (v_Mail_Conn, v_Recipient);
       UTL_SMTP.Data (
          v_Mail_Conn,
             'Date: '
          || TO_CHAR (SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss')
          || crlf
          || 'From: '
          || v_From
          || crlf
          || 'Subject: '
          || v_Subject
          || crlf
          || 'To: '
          || v_Recipient
          || crlf
          || crlf
          || 'some message text'
          || crlf
          ||                                                       -- Message body
            'more message text'
          || crlf);
       UTL_SMTP.Quit (v_mail_conn);
    EXCEPTION
 
       /* Catch exceptions */
       --WHEN OTHERS THEN         
    END;

Unique Values – Ruby on Rails

Just a quick post on how to select unique values in rails using the uniq operator:

1
2
3
4
5
6
7
8
9
10
11
#All recent categories
<% recent_categories = Category.joins(:products).where('products.user_id = ?', current_user.id).order('products.created_at desc') %>
 
#Results
Cars
Trucks
Cars
Technology
Phones
Technology
...
1
2
3
4
5
6
7
8
#Unique recent categories
<% recent_categories = Category.joins(:products).where('products.user_id = ?', current_user.id).order('products.created_at desc').uniq %>
 
Cars
Trucks
Technology
Phones
...

ERROR: column “category” does not exist

I’ve recently switched from SQLite3 to PostGreSQL and came across the following error this morning:

my_app_development=> select category from codes;
ERROR:  column "category" does not exist
LINE 1: select category from codes;

The following post solved the issues in one sentence:

http://archives.postgresql.org/pgsql-novice/2007-01/msg00032.php

Yes. In postgres, unquoted column and table names are converted to lower case.

The user also added that when using PostGreSql you should either be always, or never using quotes around column names.

undefined method `to_sym’ for nil:NilClass – Ruby on Rails Migration

While trying to do a migration today I received the following message:

undefined method `to_sym’ for nil:NilClass

#After running a trace (rake db:migrate –trace)
undefined method `to_sym’ for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing’

This was the migration:

class AddDefaultValuesToFeedbacks < ActiveRecord::Migration
  def change
    change_column :stores, :total_feedbacks, :integer, :default => 0
    change_column :stores, :rating, :decimal, :precision => 8, :scale => 2, :default => 0
  end
end

Unfortunately this problem also prevented me from performing any other migrations on the table. I attempted deleting all relevant migration files and then re-running them, restarting the server and rolling back to a previous migration – none of which worked.

Eventually I resorted to exporting the dataset, dropping the table via sqlite3 and recreating it. Thankfully this seems to have worked. The only hint I’ve come across that may explain the cause of this problem, other than typos or referring to non-existant columns, is that it can occur if a migration is screwed over before it finishes and fails to rollback properly.

If anyone else has any concrete answers, please let me know in the comments!

How to Edit a Message Catalog Definition – PeopleSoft

Editing a message catalog definition in PeopleSoft is pretty straight forward, simply browse to the following menu path:

PeopleTools > Utilities > Administration > Message Catalog

Enter your message set number into the prompt. Note that if you do not know your message set number you can use the following to find it:

1
2
3
4
5
6
7
8
SELECT *
FROM PSMSGCATDEFN
WHERE MESSAGE_SET_NBR = '12345'
      AND MESSAGE_NBR = '12345';
 
SELECT *
FROM PSMSGCATDEFN
WHERE MESSAGE_TEXT LIKE '%what your message is%';

Once you have your message simply edit the text and description appropriately then save!