Windows 10

This morning i started my Windows 8.1 pc , and noticed a new icon on the status bar:

What is, i thinked..and opening:

This guided wizard essentially requests your email.
Since the Windows 1.0 times (the one where the windows were not overlappable… 30 years ago, it used it!) it is the first free Windows major upgrade.

Categories: Uncategorized

Dynamic parameters in SQL IN

The SQL IN is one of the universally implemented keyword, for example

SELECT * FROM Customers WHERE STATE IN ('IL', 'AR')

This is the common syntax, but sometimes is requested to have the IN list dynamic.
In Microsoft Sql Server could be used an function, for example

CREATE FUNCTION [dbo].[GetStates](
)
    RETURNS @arrValues table(val char(2))
AS
BEGIN
   INSERT INTO @arrValues (val) VALUES ('IL')
   INSERT INTO @arrValues (val) VALUES ('AR')
END

Then can be used

SELECT * FROM Customers WHERE STATE IN (SELECT val FROM dbo.GetStates())

Unfortunately (still searching for an workaround…) this syntax cannot be used in grouping , for example

SUM(CASE 
   WHEN [groupcomponentcode] IN ( '1004', '1003', '1005', '1063' ) THEN Amount 
   ELSE 0 
END)  AS EngineGroup

is working , instead

SUM(CASE 
   WHEN [groupcomponentcode] IN (SELECT val FROM dbo.SomeFunc()) THEN Amount 
   ELSE 0 
END)  AS EngineGroup

gives the error
‘Cannot perform an aggregate function on an expression containing an aggregate or a subquery’

Categories: SQL Server

Azure Tools 2.6 troubles

Some days ago i noticed that was available the 2.6 update of Azure Tools for Visual Studio 2013, and obviously..immediately installed.
Until now i was working on Windows Phone 8.1 projects, then i decided to try an Universal App, and ..error: “No exports were found that match the constraint…”, with a plethora of other error messages; project not created.
After some struggle, the solution : the uninstallation of the Azure Tools 2.6 for Vs 2013, leaving the previous versions 2.5 and 2.4 installed.
Featured image
After that, the creation of an Universal App is successfully.
I’m using Windows 8.1 in English, Visual Studio 2013 in English, both with the latest updates: how is possible that in Microsoft no one got this error while trying to create an Universal App, the new Microsoft Verb ?

Categories: Azure

Azure Fixit demo..fix

Microsoft has a lot of material for the Azure beginners, for example there is an interesting ebook with a page for the course code.

In the downloadable code there are some PowerShell scripts , that prepares the demo environment (SQL db, web app) in your Azure subscription.

These scripts are in the \fixit\C#\Automation folder.

It must be installed the Azure Powershell extensions, this can be done from the Web Platform installer.

The instructions say that must be launched the New-AzureWebsiteEnv.ps1 , but if you try, does not work.

The code in New-AzureWebsiteEnv.ps1 and New-AzureSql.ps1 must be corrected, where there is the line

Get-AzureSubscription -Current

Must be substituted with

Get-AzureSubscription -Current -ExtendedDetails

It seems that from a certain point in time is necessary to add the ExtendedDetails switch, otherwise you don’t get every needed bit.

But wait, don’t launch the script now.

The Azure PowerShell has a local cache, that could not be correctly initialized.

Then go to C:\Users\[windows user]\AppData\Roaming\Windows Azure Powershell, delete everything.

Launch the PowerShell command line (better if as Administrator, i have done this but i don’t know if really needed)

Write at the prompt Get-AzurePublishSettingsFile and press return.

Immediately appears a Window , with the login request if needed, where is requested to download a file.

Still In the Azure Powershell command write Import-AzurePublishSettingsFile, return: you are prompted for the previously downloaded file.

Notice that in C:\Users\[windows user]\AppData\Roaming\Windows Azure Powershell appears some files.

Now in the Azure PowerShell command you can make a cd (ms-dos Change Directory i mean…), then launch

.\New-AzureWebsiteEnv.ps1

This approach worked for me.

Categories: Azure

Oracle development notes

After many years (Oracle 8..) i’m back to develop on Oracle (using Microsoft Windows). So, after some problem, here a little quick guide for starting with the current versions (April 2015). Before of all, must be installed the java JDK, the 64 bit package jdk-8u40-windows-x64.exe or 32 (jdk-8u40-windows-i586.exe) depending from your system. Then must be installed , as already written in this post, the ODAC component: in this page for the 64 bit version (is recommended the version with installer, not the Xcopy version) ; the 32 bit version here. The main product for the developer is Oracle SQL Developer from here. The Oracle SQL Developer is installed by default in c:\app, the folder c:\app\client\<your_windows_user_name>\product\12.1.0\client_1\Network\Admin is the default place where to place the tnsnames.ora file, needed for the Oracle connections. We have 2 servers, one for development and the other is the official database:

VJSVIL =
  (DESCRIPTION =
        (ADDRESS =
          (COMMUNITY = tcp.world)
          (PROTOCOL = TCP)
          (Host = 10.86.13.xxx )
          (Port = 1521)
        )
    (CONNECT_DATA = (SID = VJSVIL)
    )
  )

VJ4SAP =
  (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = srv-vrj)(PORT = 1521))
     (CONNECT_DATA =
       (SERVER = DEDICATED)
       (SERVICE_NAME = XE)
     )
   )

Note that the development entry is using the IP , instead for the official database is used the hostname. If must be used the hostname for some reason (as in this case) could be useful to map the hostname to the ip in C:\Windows\System32\drivers\etc\hosts, in our case:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#        127.0.0.1       localhost
#        ::1             localhost
10.86.13.xxx        srv-vrj

In order to work, it must be verified that the 1521 port is opened in the firewalls. Launching SQLDeveloper there are 2 problems that you can encounter. The first is the language , for example the software is working in French or Italian and in the preferences menu there is nothing for the language. The language setting in English is done by adding the line AddVMOption -Duser.language=en In the file <path where you unzipped SQL developer>\sqldeveloper\bin\sqldeveloper.conf; another strange problem could be the error ORA-01882: timezone region not found.
This is resolved by adding in sqldeveloper.conf AddVMOption -Duser.timezone=CET.
In SQL Developer we can add a connection selecting the TNS item: 02-04-2015 15-51-19 And we can expand and see the list of tables, views, etc. below the connection name node. 02-04-2015 16-15-14

maxJsonLength property

I was working on a asp:DataGrid table , where in every cell there is an asp:Textbox for immediate editing (think to a sort of Excel).
Then with an html button is called the javascript method save:

function save() {
    $get('ContentPlaceHolder1_UpdateProgress1').style.display = 'block';
    var strSql = "";
    var strPartSql = "";
    $("input.editqt").each(function () {
        var strHtmlId = this.id;
        var arrValues = strHtmlId.split("_");
        var strId = arrValues[1];
        var strValue = $("#" + strHtmlId).val();
        if (strValue.trim() === "")
            strValue = "0";
        strPartSql = "UPDATE TSG123_VoyageRes SET Qt = " + strValue + " WHERE ID_Voyage_Res = " + strId + "; ";
        strSql += strPartSql;
    });
    PageMethods.SaveMatrix(strSql, saveCallback, saveErrorCallback, "save");
}

function saveCallback(result, response, context) {
    $get('ContentPlaceHolder1_UpdateProgress1').style.display = 'none';
    window.alert("Save success.");
}

function saveErrorCallback(result, response, context) {
    $get('ContentPlaceHolder1_UpdateProgress1').style.display = 'none';
    if (result._timedOut)
        window.alert("Timeout saving");
    else {
        if (result !== null)
            window.alert(result.get_message());
        else
            window.alert("Error saving.");
    }
}

The javascript code calls an PageMethod (the web site uses ASP.NET 4, VB.NET , Microsoft Ajax Toolkit), defined as:

<System.Web.Script.Services.ScriptMethod(), System.Web.Services.WebMethod()> _
Public Shared Sub SaveMatrix(ByVal sql As String)
    UserFrameworkClass.AccessDB.Database.SetData(sql, Data.CommandType.Text)
End Sub

In practice from the javascript side is generated (not the best method..) a long SQL string, in the Page method is launched “as is” into SQL Server.
At a certain point the datagrid became bigger, and trying to save , crash: error from javascript:
“Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.”
The solution was to add these lines in web.config:

<system.web.extensions>
  <scripting>
    <webServices>
      <jsonSerialization maxJsonLength="2147483647"/>
    </webServices>
  </scripting>
</system.web.extensions>

No more errors, until these pages will be rewritten in a more solid manner.

Arbitrary values in asp:Datagrid

Working at a ships loading planner, i received this request: we can have more work turns, for every turn one or more squads (from 1 to 5).

But there should be an optional special squad , the “0” squad, that must be represented with the “SA” string; note also that only on the first row for every turn must be visible an Word export icon.

The work turn on the db is an Int.. how to write “SA”?

We are speaking of an .NET 4 solution, using VB.NET, the DataGrid is defined as

<asp:DataGrid ID="DG" runat="server" AutoGenerateColumns="False" ShowHeader="true"
    EnableViewState="true" CssClass="DGBorder" Width="99%" Height="1%" HorizontalAlign="left">
    <AlternatingItemStyle CssClass="DGRow2" />
    <SelectedItemStyle CssClass="DGSelect" />
    <ItemStyle CssClass="DGRow1" />
    <HeaderStyle />
    <Columns>
        <asp:BoundColumn DataField="Day" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}">
            <ItemStyle CssClass="DGBorder" Width="200px" HorizontalAlign="Left" />
            <HeaderStyle HorizontalAlign="Center" Width="200px" />
        </asp:BoundColumn>
        <asp:BoundColumn DataField="Turn" HeaderText="Turn">
            <ItemStyle CssClass="DGBorder" Width="100px" HorizontalAlign="Left" />
            <HeaderStyle HorizontalAlign="Center" Width="100px" />
        </asp:BoundColumn>
        <asp:BoundColumn DataField="Hours" HeaderText="Hours">
            <ItemStyle CssClass="DGBorder" Width="3em" HorizontalAlign="Center" />
            <HeaderStyle HorizontalAlign="Center" Width="3em" />
        </asp:BoundColumn>
        <asp:BoundColumn DataField="Squad" HeaderText="Squad">
            <ItemStyle CssClass="DGBorder" Width="100px" HorizontalAlign="Center" />
            <HeaderStyle HorizontalAlign="Center" Width="100px" />
        </asp:BoundColumn>
        <asp:ButtonColumn DataTextField="Squad" HeaderText="Fold" DataTextFormatString="<img src=Imgs\word.png border=0>" CommandName="PrintFold">
            <ItemStyle CssClass="DGBorder" Width="100px" HorizontalAlign="Center" />
            <HeaderStyle HorizontalAlign="Center" Width="100px" />
        </asp:ButtonColumn>
    </Columns>
</asp:DataGrid>

The solution is the SetRenderMethodDelegate method:

Protected Sub DG_ItemCreated(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DG.ItemCreated
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then
        Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
        If drv Is Nothing Then
            Exit Sub
        End If
        If strDataRif = String.Empty Then
            strDataRif = drv.Row("Day").ToString()
            strTurnoRif = drv.Row("Turn").ToString()
        End If
        strTempData = drv.Row("Day").ToString()
        strTempTurno = drv.Row("Turn").ToString()
        If strTempData <> strDataRif Or strTempTurno <> strTurnoRif Or boolForceFirst Then
            strDataRif = strTempData
            strTurnoRif = strTempTurno
            boolForceFirst = False
            ' 3 = position of column, starting from 0 , in DataGrid
            e.Item.Controls(3).SetRenderMethodDelegate(New RenderMethod(AddressOf RenderCustom))
        Else
            e.Item.Controls(4).Controls(0).Visible = False
        End If
    End If
End Sub

Protected Sub RenderCustom(ByVal writer As System.Web.UI.HtmlTextWriter, ByVal Container As System.Web.UI.Control)
    If DirectCast(Container, System.Web.UI.WebControls.TableCell).Text = "1" Then
        writer.Write("1")
    Else
        writer.Write("SA")
    End If
End Sub

If we asked to create the SA squad, we have 0 as number and then must be changed with “SA” , otherwise the squad numbering begins with 1 and must not be changed.
The result:

grid

Strange behaviors in Crystal

I found today a strange behavior with Crystal Reports .NET , using Visual Studio 2010.
In a recordsource there are 2 numeric (integer) columns that were displayed in the preview window, inside Visual Studio.
At runtime for these 2 colums, nothing: no values displayed, even the headers.
This in a subreport; this one in origin had the same SQL of the main report.
Then the datasource of the subreport was changed, some columns previously used in the report was deleted, substituted with other columns, with different names.
I tried even to change the original subreport SQL (a JOIN between 2 CTE, inside every CTE a PIVOT) with a plain SQL (SELECT ‘value’ AS columnname) but without success: still no data displayed at runtime inside the subreport.
The solution is very strange, a Crystal formula (Vb syntax):

If IsNull({Command.TotalTSG}) then
    formula = 0
else
    formula = {Command.TotalTSG}
end if

If the fields are placed directly in the Crystal editor, data visible in preview but nothing at runtime; instead it works also at runtime with Crystal formulas: data displayed.
Note: all of the remaining fields (also integers) are displayed if placed directly on the report (but are fields in common as name between the main and the subreport), even without a formula.
Mysteries of Crystal Reports.

Outlining in Eclipse

In Visual Studio 2013 by right clicking the code there is an useful menu for code outlining


Is so useful CTRL+MO…

In Eclipse Luna i struggled for a while in order to find the same feature, not easy to discover;

CTRL+SHIFT+/ on numeric keypad is the same of CTRL+MO on Vs2013; CTRL+SHIFT+* (on numeric keypad) is the same of CTRL+ML

The trick works only if is activated the folding: by right clicking on the line numbers appears the menu, with the folding activated are visible the controls (in yellow in the image) for expanding and retracting the code.

eclipsefolding

Categories: .NET, Android
Follow

Get every new post delivered to your Inbox.