Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

Wednesday, December 21, 2016

Hi,
Microsoft Dynamics CRM Database can be giant because many reason..
The main reason is files into CRM DB.

Attached to this article two queries.
First query to get database size per table.
Second query to get number of records – filee in Annotation table.

Enjoy,
Rami Heleg

SELECT 
 so.object_id AS ObjectID, 
 so.name AS ObjectName,        
 (CONVERT(decimal(20,4),(SUM (ps.reserved_page_count) * 8))) / 1024 As Reserved_MB, 
 (CONVERT(decimal(20,4),SUM ( 
             CASE 
                   WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) 
                   ELSE ps.lob_used_page_count + ps.row_overflow_used_page_count 
             END 
             ) * 8)) / 1024 As Data_MB, 
 (CONVERT(decimal(20,4),(CASE WHEN (SUM(used_page_count)) > 
             (SUM(CASE 
                   WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) 
                   ELSE ps.lob_used_page_count + ps.row_overflow_used_page_count 
             END 
             )) THEN (SUM(used_page_count) -           
             (SUM(CASE 
                   WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count) 
                   ELSE ps.lob_used_page_count + ps.row_overflow_used_page_count 
             END 
             ))) ELSE 0 END) * 8)) / 1024 As Index_MB, 
 (SUM ( 
             CASE 
                   WHEN (ps.index_id < 2) THEN ps.row_count 
                   ELSE 0 
             END 
             )) AS [RowCount] 
 FROM sys.dm_db_partition_stats AS ps 
 INNER JOIN sys.objects AS so ON so.object_id = ps.object_id 
 WHERE so.object_id > 100 
 GROUP BY so.object_id, so.name 
 ORDER BY [Reserved_MB]Desc

=============================================================

SELECT  e.logicalname, e.ObjectTypeCode,COUNT( e.ObjectTypeCode) AS NumberOfRecords 
FROM Annotation a inner join Entity e
on a.ObjectTypeCode = e.ObjectTypeCode
GROUP BY  e.ObjectTypeCode , e.logicalname
order by NumberOfRecords desc

Wednesday, November 30, 2016

Houston, we have a problem – Aysnc Service is down.. Unable to restart.


Houston, we have a problem – Aysnc Service is down.. Unable to restart.
After install Framework in CRM Database server and restart we Got a major problem Async Maintaince Service is down and failed to upload..

 
Error message:
  
Host XXX : failed while monitoring asynchronous operations queue. Exception: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.

at Microsoft.Crm.Asynchronous.JobDataAccess.<>c__DisplayClassc.<RetrieveSqlServerName>b__a(Object[] values)

at Microsoft.Crm.Asynchronous.JobDataAccess.ExecuteSqlOrganizationScopeAndProcessRecords(IDbCommand command, Guid organizationId, RecordProcessor recordProcessor)

at Microsoft.Crm.Asynchronous.JobDataAccess.RetrieveSqlServerName(Guid orgId)

at Microsoft.Crm.Asynchronous.JobDataAccess.UpdateJobTargetServer(AsyncJob job)

at Microsoft.Crm.Asynchronous.JobDataAccess.GetNextJob(IList`1 orgsAvailableForMaintenance, DateTime startCycleTime, Int32 maxJobsToReturn)

at Microsoft.Crm.Asynchronous.JobDataAccess.GetNextJobInAppLock(IList`1 orgsAvailableForMaintenance, DateTime startCycleTime, Int32 maxJobsToReturn)

at Microsoft.Crm.Asynchronous.JobDataAccess.SelectJobs(DateTime startCycleTime, Int32 maxJobsToRetrieve)

at Microsoft.Crm.Asynchronous.JobManager.RetrieveAndQueueJobs()

at Microsoft.Crm.Timers.Timer.InvokeElapsedWithCancellationToken(Object state)

at Microsoft.Crm.Timers.Timer.InvokeElapsed()

at Microsoft.Crm.Timers.Timer.TimerProcessor.ExecuteTimers(Object data)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart(Object obj)


 

 steps to fould the reason:

  1. Use CRM Trace when try to restart the service got the error:

  2. crm 2011 failed while monitoring asynchronous operations queue. Exception: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.
  3. In CRM we have 3 organization , disabled specific one Async successs to restart.. then I checked MSCRM_Config – organization table looks perfect like all other organization..

  4. Backup problematic organization DB and remove the organization + try to import this organization got the next error message

The instance name must be the same as computer name.

 


The reason for this problem found by running this command @@servername in sql management…



How to solve:
 
 
 
select @@servername - result is NULL (should contain server name)

SP_DROPSERVER "SERVERDBNAME"

SP_ADDSERVER "SERVERDBNAME ", local


 
restart the MSSQLSERVER service



Async Maintanice servce back to life.
 
 
Enjoy,

Rami Heleg

+972-52-5695114
 

Thursday, May 21, 2015

Steps to upgrade CRM 2013 – CRM 2016

1.       Back Database.
2.       Remove SQL Reporting extension from server

3.       Install CRM 2016: Downloaded from http://www.microsoft.com/en-us/download/details.aspx?id=42637


4. Insert CRM key.

5. Accept License agreement

6. Select organization to upgrade..
   if you have more organization after finish to upgrade to 2016 open deployment manager and update organization
 7. Define service account.. for instance define sand box in specific user







8.   Install SetupSrsDataConnector.exe from  CRM 2016 Files\SrsDataConnector










1.       Upgrade organizations to 2016
3.       Install framework 4.5.2 
4.       Update plugin to new version (4.5.2)
5.        Test CRM.

Implement nolock in Fetch

By default SQL server defined to lock records when execute query and rows selected until finish to execute.. problem when we have many records.

to prevent lock records in CRM, DBA allow to define all database to work with no-lock and we have another option to request fetch with no lock.

Example:









Enjoy,
Rami Heleg

Database: Command to get Entities list related to Solution

//LangNumber  = 1031, 1036, 1037 etc... language code
//SolutionName = solution name

select DISTINCT  e.LogicalName ,l.label, s.UniqueName from entity e right join   LocalizedLabel l
on e.entityid = l.objectid inner join SolutionBase s
on e.SolutionId = s.SolutionId inner join SolutionComponentBase sb
on sb.SolutionId = s.SolutionId where l.LanguageId=LangNumber
and l.ObjectColumnName ='LocalizedName' and  s.UniqueName = 'SolutionName'


Enjoy,
Rami Heleg

Import solution failed.. get message "solution With Id = e25cd1e4-54ff-4bdc-890b-31b1d8c3c720 Does Not Exist"

When try to import solution get the next message:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: solution With Id = e25cd1e4-54ff-4bdc-890b-31b1d8c3c720 Does Not ExistDetail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147220969</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
  <Message>solution With Id = e25cd1e4-54ff-4bdc-890b-31b1d8c3c720 Does Not Exist</Message>
  <Timestamp>2012-08-09T10:45:33.7307214Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText i:nil="true" />
</OrganizationServiceFault>

To  solve this issue please open SQL Management and run the command 

DECLARE @SolID NVARCHAR(MAX)
SET @SolID = 'e25cd1e4-54ff-4bdc-890b-31b1d8c3c720'
SELECT
      t.name AS table_name,
      SCHEMA_NAME(schema_id) AS schema_name,
      c.name AS column_name,
      'SELECT * FROM ' + t.name + ' WHERE ' + c.name + ' = ''' + @SolID + '''' as Query
FROM sys.tables AS t
      INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%SolutionId%'
ORDER BY schema_name, table_name;

after find the record remove the record from database and try to import the solution again.

enjoy,
Rami Heleg

Wednesday, May 20, 2015

Restore CRM organization - Database

Restore CRM organization - Database 


1.       Open SQL and select Restore Database…

2.       Select Device and select database backup file

3.       Run the Restore – press OK


4.       Open deployment manager and press Import organization




5.  CRM is ready


Enjoy,
Rami Heleg

Monday, August 22, 2011

Get Database - tables size

How to get database size:

run this script:

SELECT
so.object_id AS ObjectID,
so.name AS ObjectName,       
(CONVERT(decimal(20,4),(SUM (ps.reserved_page_count) * 8))) / 1024 As Reserved_MB,
(CONVERT(decimal(20,4),SUM (
            CASE
                  WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count)
                  ELSE ps.lob_used_page_count + ps.row_overflow_used_page_count
            END
            ) * 8)) / 1024 As Data_MB,
(CONVERT(decimal(20,4),(CASE WHEN (SUM(used_page_count)) >
            (SUM(CASE
                  WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count)
                  ELSE ps.lob_used_page_count + ps.row_overflow_used_page_count
            END
            )) THEN (SUM(used_page_count) -          
            (SUM(CASE
                  WHEN (ps.index_id < 2) THEN (ps.in_row_data_page_count + ps.lob_used_page_count + ps.row_overflow_used_page_count)
                  ELSE ps.lob_used_page_count + ps.row_overflow_used_page_count
            END
            ))) ELSE 0 END) * 8)) / 1024 As Index_MB,
(SUM (
            CASE
                  WHEN (ps.index_id < 2) THEN ps.row_count
                  ELSE 0
            END
            )) AS [RowCount]
FROM sys.dm_db_partition_stats AS ps
INNER JOIN sys.objects AS so ON so.object_id = ps.object_id
WHERE so.object_id > 100
GROUP BY so.object_id, so.name
ORDER BY [Reserved_MB]Desc

Thanks,
Rami Heleg.