Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Wednesday, 14 November 2012

Copy Your Database on Same Server (Windows Azure SQL Database)

to copy your database to a new database on the same server

CREATE DATABASE Database1B AS COPY OF Database1A;

Tuesday, 30 October 2012

Error!!! Could not load file or assembly

When you get this error like I did, and it tells you the assembly file version or error says The located assembly's manifest definition does not match the assembly reference.



you'll have to follow the steps to get the dll files from windows assembly GAC
my example is about the ReportViewer.ProcessingObjectModel version so I'll use this. However you can use whatever is missing dll in your error

Open a command prompt in Administrator mode


Type cd \windows\assembly\gac_msil\Microsoft.ReportViewer.ProcessingObjectModel press Enter

Type dir so it lists the files/folders inside and press Enter and check your required version folder is available


in my case my required version was 11.0.0.0__89845dcd8080cc91 so I typed cd 11.0.0.0__89845dcd8080cc91 and press Enter

you'll be able to find Microsoft.ReportViewer.ProcessingObjectModel.dll in this folder

now we will copy this dll type command copy*.dll c:\dll (or any folder you wish to copy) and press Enter

now the dll is copied to your specified folder and you can use it as a reference in your project folder.





Tuesday, 25 October 2011

Convert SSL Certificate .cer to .pfx

If you were like me working on Azure projects and suddenly was required to upload your SSL certificate and hit the dead end trying to figure out how to convert the file to .pfx, you have come to the right place, follow these simple steps and you'll be good to go.

PowerShell Script
$c = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\mycert.cer")
$bytes = $c.Export("Pfx","password")
[System.IO.File]::WriteAllBytes("c:\mycert.pfx", $bytes)

and just incase if you got the error cannot find type [System.Security.Cryptography.X509.....

Try running this to see if you have the System.dll loaded (should be by default):
[AppDomain]::CurrentDomain.GetAssemblies() |
    Where {$_.Location -match '\\System\\'}

If it is loaded then this command should show the X509Certificate2 type:
[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location -match '\\System\\'} |
%{$_.GetExportedTypes()} | Where {$_.Name -match 'X509Cert'}
If the System.dll isn't loaded (which would be odd) try loading it:
Add-Type -AssembyName System

Friday, 5 August 2011

Get a list of all Triggers in a SQL Database

SELECT S2.[name] TableName, S1.[name] TriggerName, CASE WHEN S1.deltrig > 0 THEN 'Delete' WHEN S1.instrig > 0 THEN 'Insert' WHEN S1.updtrig > 0 THEN 'Update' END 'TriggerType' FROM sysobjects S1 JOIN sysobjects S2 ON S1.parent_obj = S2.[id] WHERE S1.xtype='TR'
The above doesn't correctly identify INS, UPD and DEL. Try:

SELECT S2.[name] TableName, S1.[name] TriggerName, CASE WHEN S2.deltrig = s1.id THEN 'Delete' WHEN S2.instrig = s1.id THEN 'Insert' WHEN S2.updtrig = s1.id THEN 'Update' END 'TriggerType' , 'S1',s1.*,'S2',s2.* FROM sysobjects S1 JOIN sysobjects S2 ON S1.parent_obj = S2.[id] WHERE S1.xtype='TR'

Wednesday, 20 July 2011

How to create threads with .net and Azure Web Role

Dim t As New Threading.Thread(AddressOf ThreadTask)
t.IsBackground = True
t.Start()

and then create your ThreadTask

Private Sub ThreadTask()
'do your routine here
End Sub

Monday, 18 July 2011

Best way to Zoom map to include all Pushpins

add the following to your map function

var locs = new Array();
/* Repeat the next 2 lines of code as neccessary */
var loc = new VELatLong(<latitude>, <longitude>);
locs.push(loc);
/* End Repeat */
map.SetMapView(locs);

Writing to Azure Local Storage

You will need to modify ServiceDefinition.csdef add the following lines

<LocalResources>
<LocalStorage name="LocalTempFolder" cleanOnRoleRecycle="false" sizeInMB="5" />
</LocalResources>

and then you can access the path this way in your code

Dim localResource As LocalResource = RoleEnvironment.GetLocalResource("LocalTempFolder")
Dim pathToReadWriteFolder = localResource.RootPath

Wednesday, 13 July 2011

Javascript Popup window causes parent font size increase?

If you are usnig Javascript popup window and its disturbing your parent font sizes use the ScriptManager.RegisterStartupScript instead.

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "newWindow", "window.open('MyPage.aspx?ID=" + MyID + "','_blank','status=1,toolbar=0,menubar=0,location=1,scrollbars=1,resizable=1,width=30,height=30');", true);
   

Monday, 20 June 2011

SQL Azure DATETIME Functions

Microsoft SQL has always included a number of date and time functions.  These results of these functions were always based on the operating system for the machine the SQL server was running on.  But what results will you get when you’re dealing with SQL Azure?

The server(s) are all virtual.

They are all based on UTC, Coordinated Universal Time.  Yes, I know the acronym should be CUT.  Just go to Wikipedia if you want to try and make sense of this.

Since all these functions will run based on UTC, you’ll always get the same results, no matter which data center you choose to be your primary.

The table below shows the results from the following query run against a SQL Azure instance hosted in North Europe on 20th June 2011 07:08:53 UTC.

SELECT
    SYSDATETIME() as SYSDATETIME,
    SYSDATETIMEOFFSET() as SYSDATETIMEOFFSET,
    SYSUTCDATETIME() as SYSUTCDATETIME,
    CURRENT_TIMESTAMP as currenttimestamp,
    GETDATE() as getdate,
    GETUTCDATE() as getUTCdate;


Query
SYSDATETIME() 2011-06-20 07:08:53.1026073
SYSDATETIMEOFFSET() 2011-06-20 07:08:53.1026073 +00:00
SYSUTCDATETIME() 2011-06-20 07:08:53.1026073
CURRENT_TIMESTAMP 2011-06-20 07:08:53.113
GETDATE() 2011-06-20 07:08:53.113
GETUTCDATE() 2011-06-20 07:08:53.100

If you are like me, whenever you deal with international users, you already changed your servers to UTC, so taking this into consideration for SQL Azure should be nothing new.  If you’re not used to this.  Perhaps now is the time to consider the benefits to having your server use UTC, store UTC + offsets in your tables, and allow users to run with multiple time zones.

It sure makes scheduling easier that way.  Or at least it beats trying to figure out what time to hold a meeting between London the US and Mexico, both before and after Daylight Savings time kicks in!

Thursday, 16 June 2011

Windows Azure Reporting missing .dll

I deployed my project successfully to Windows Azure, but got a surprise when I ran reports, they gave error mentioning a missing assembly Microsoft.ReportViewer.ProcessingObjectModel.dll

now I new how to add references to Microsoft.ReportViewer.Common.dll and Microsoft.ReportViewer.WebForms.dll but I couldn't find the missing one anywhere, but with a help from a colleague here is the workaround.

how did I get the third assembly, Microsoft.ReportViewer.ProcessingObjectModel.dll?

Apparently this assembly was found only in the GAC. Here is how you copy the file in the GAC :
  1. Open command prompt (run as Adminsitrator)
  2. cd C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.ProcessingObjectModel
  3. do dir.
  4. You see either one or both of the following folder:
    8.0.0.0__b03f5f7f11d50a3a
    9.0.0.0__b03f5f7f11d50a3a
    10.0.0.0__b03f5f7f11d50a3a
  5. cd to one of them, and do dir.
  6. You should see the Microsoft.ReportViewer.ProcessingObjectModel.dll assembly.
  7. You can perform copy operation to your preferred destination folder.

MsgBox or MessageBox Error on Windows Azure

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
so if you hit the error above, you have used MsgBox or MessageBox dialogue boxes to confirm the user click.

well the solution is simple use Ajax ConfirmButton 

see the link below for syntax:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ConfirmButton/ConfirmButton.aspx

The report definition for report 'path' has not been specified

So I guess you hit the error like it did, reports were working fine in your local project, but when uploaded to windows azure they stopped working.

The full errormessage is:
The report definition for report 'path' has not been specified. Could not find file 'path'.

This error might occur when you try to run a local report (rdlc).

The solution is to set the property "Build Action" of the rdlc to "Content". Now your installer will copy the physical rdlc.




you have to mark all .rdlc files in your project as Content.

SSRS 2008 Tablix control Repeat Column Headers does not work

If you faced the issue which I have faced, that you created your nice looking report, and next thing you realise the Column headers do not repeat, no matter what you did was not good enough to fix it.

Here is the solution:

Select the Tablix that you want to repeat column headers for by clicking on it.

At the bottom of the screen, find the "Row Groups" and "Column Groups" section.


Click the small drop-down-arrow on the right side of that section, and select the Advanced Mode.



Now you'll see additional lines called (static) in rows and columns groups.



In the "Row Groups" section, locate the top-outermost "static" row and click on it.


In the properties pane, you need to set the following properties:

KeepTogether = True
KeepWithGroup = After
RepeatOnNewPage = True

All of these properties must be set for this to work properly.

Good luck!

Wednesday, 1 June 2011

MS SQL Create Clustered Index on All Tables

I was creating Windows Azure project, and was faced when uploading the database to SQL Azure, that many of the tables didn't have Clustered Indexes, thought of saving some time by writing a script.

This script will create Clustered Index on all tables which do not have clustered index.


DECLARE @table_name VARCHAR(50); -- table name 
DECLARE @col_name VARCHAR(50); -- column name 
DECLARE @idx_name VARCHAR(256); -- name for index 
DECLARE @cmd1 NVARCHAR(256); -- command syntax

DECLARE db_cursor CURSOR FOR 
SELECT     sys.sysobjects.name AS tbName, sys.syscolumns.name AS colName, 'idx_' + sys.sysobjects.name + '_' + sys.syscolumns.name as idxName
FROM         sys.sysobjects INNER JOIN
                      sys.syscolumns ON sys.sysobjects.id = sys.syscolumns.id INNER JOIN
                      sys.systypes ON sys.syscolumns.xtype = sys.systypes.xtype LEFT OUTER JOIN
                      sys.indexes ON sys.sysobjects.id = sys.indexes.object_id
WHERE     (sys.sysobjects.xtype = 'U')  AND (sys.systypes.name = 'int') AND (sys.syscolumns.colid = 1) AND
                      (sys.indexes.index_id = 0)
ORDER BY tbName;

OPEN db_cursor;  
FETCH NEXT FROM db_cursor INTO @table_name, @col_name, @idx_name;  

WHILE @@FETCH_STATUS = 0  
BEGIN  

SET @cmd1 = 'CREATE CLUSTERED INDEX ' + @idx_name + ' ON ' + @table_name + '(' + @col_name + ');'

EXECUTE sp_executesql @cmd1

       FETCH NEXT FROM db_cursor INTO @table_name, @col_name, @idx_name;
END  

CLOSE db_cursor; 
DEALLOCATE db_cursor;

SQL Find tables without Clustered Indexes

USE AdventureWorks ----Replace AdventureWorks with your DBName
GO

SELECT DISTINCT [TABLE] = OBJECT_NAME(OBJECT_ID)
FROM SYS.INDEXES
WHERE INDEX_ID = 0
AND OBJECTPROPERTY(OBJECT_ID,'IsUserTable') = 1
ORDER BY [TABLE]
GO

Create SSL test Certificate

Open a Visual Studio Command Prompt


Change your active directory to the location where you wish to place your certificate


Enter the following command

makecert -r -pe -n "CN=AzureSSL" -sky 1 "azuressl.cer" -sv "azuressl.pvk" -ss My




after the process has succeeded


Now enter the following command

pvk2pfx -pvk "azuressl.pvk" -spc "azuressl.cer" -pfx "azuressl.pfx" -pi password1


and you are good to go, you have your test certificate