How to properly do an export and import of a database

Posted on Updated on

Last year, I came across a database that had 2 corrupted tables.  Fortunately, these 2 tables were actually not used so it can safely get ignored.  However with those 2 corrupted tables still in the database, I could not get a passing result when doing DBCC CheckDB against the database.  And I have tried exporting the database into an “empty” database created by the same application without success.


Here is how I fixed my problem:

Step 1 – Export Database

  • Launch SSMS as an admin and login as SA if possible or with a user with sysadmin rights.
  • Right-click on the database and select Tasks > Export Data.  Click Next.
  • Select SQL Server Native Client 11.x under Data Source, specify the Server Name, use SA (preferred).  And then select the source database.  Click Next.


  • Under Destination, select SQL Server Native Client 11.x.  And specify the other values.
  • Click New under Database to create a new DB where the data will be exported to.  Click Next.
  • In the next screen, select Copy data from one or more tables or views.  Click Next.

Table Copy

  • In the next screen, select all tables you would like to export and select Next.  I omitted the Views at this stage as I do not need them.  And leave all the rest as default and click on Finish to start the export process.

Step 2 – Working on the Empty Database

  • In my case, the application my database was using has the ability to create an empty database with all views, schemas, keys, etc.  My only problem is that it then also populates some of the tables with default data.  I tried to truncate these tables got FK restrictions would not allow me.  So I had to run a delete from on all tables.

use <empty_db>

EXEC sp_msforeachtable @command1=”delete from ?”


  • This command can also be used to make sure your database is really empty.  I have seen other posts where they suggest to delete all FKs and then delete the data and then reinstall FKs.  For me, that is too much work.

Step 3 – Importing Data into the Empty Database

  • Right-click on the Empty database, select Task > Import Data
  • Fill out the data source referencing to the exported database from the previous step.  Click Next.
  • In the Choose a Destination window, set it to the empty database.  Click Next.
  • Again select Copy data from one or more tables or views on the next screen.
  • In the next screen, select all tables.  When they are all selected, click Edit Mappings and select Enable Identity Insert.  Click Next.  And hit Finish to start the import.


You should not get any errors at this point.  But if you do, review the errors and make appropriate adjustments and try again.


——————————- Additional Info ———————————–


If you are having problems with constraints when deleting existing data on the table or when trying to import data.  Use the command below:

EXEC sp_msforeachtable @command1=”ALTER TABLE ? NOCHECK CONSTRAINT ALL”


However, you may need to know what constraints are currently set so you know what to enable later.  I use this command to show me what they are.

SELECT name, tbl=object_name(parent_obj)

FROM sysobjects

WHERE objectproperty(id, ‘CnstIsNotTrusted’) = 1



SELECT *, name, is_not_trusted

FROM sys.foreign_keys

WHERE is_not_trusted = 1



Disclaimer:  Scripts are provided AS IS, and author is not responsible with any issues resulting to usage of this script.

EVENT 25039, LS Mediation for Server Skype for Business 2015

Posted on Updated on

While I was playing around in Skype, I inadvertently caused an issue with incoming calls.  After making changes in the Topology Builder for the PSTN gateway, the error below started showing up in the logs for Skype.  And calls are no longer working.

Event 25039, LS Mediation Server

SDP negotiation failed with the Trunk.

Trunk FQDN xxxxxxx; trunk=xxxxxxxx, Reason SRTP is not enabled for Mediation Server.

Cause: The Trunk is either not configured correctly, incompatible with Mediation Server, or not certified.


History and Resolution:

Our PSTN gateway (AudioCodes 500) has 2 NICS, one facing the Shoretel or WAN side of the network and the other facing Skype.  In Skype PSTN gateways configuration for the AudioCodes gateway, I tried changing the IPv4 Address to ‘use all configured IP Addresses‘ which caused the issue.  To fix this, I set ‘Limit service usage to selected IP address‘ and I entered the IP of the AudioCodes NIC facing Skype.


I hope this post helps anyone out there having trouble configuring their skype gateways.  Please feel free to leave a comment or question.

Shoretel Call problems with Juniper SRX 220

Posted on Updated on


  • Calls to a workgroups on a different Shoretel site drops after few seconds or times out
  • Calls to an ACD queue times out
  • Call transfers don’t work
  • Phones behind Juniper SRX 220 had same issue as above when registered to a Shoregear on a different site.
  • Regular extension to extension calls work just fine


  • Phone and Shoregear switch is behind a Juniper SRX 220
  • Shoregear is on a different VLAN as the phones


  • We have worked intensively with Juniper support and what they figured out is that ALG MGCP is not correctly allowed within the Juniper SRX 220.  SRX isn’t handling the second MDCX connection for complex calls as expected. If the Shoregear is on the same VLAN as the phone, then the problem goes away.  However, there are instances where you need the Shogear to be on a separate VLAN especially when you have a multistory building and you only have 1 shoregear at the whole site.  Or if there is a Shoregear failure and you have to register the phones to a different site.


  • As of the time of this post, Juniper is still working on a fix.  But the workaround is to disable MGCP and allow MGCP related applications on the firewall.

#Disable MGCP

Set security alg mgcp disable

#Clear MGCP Sessions

clear security flow session application mgcp-ua

clear security flow session application mgcp-ca

#Allow MGCP traffic

[edit security policies from-zone trust to-zone untrust policy TR-UNTR-MGCP]

set match source-address NET-LOCAL

set match destination-address any

set match application junos-MGCP

set match application junos-MGCP-CA

set match application junos-MGCP-UA

set then permit

[edit security policies from-zone untrust to-zone trust policy UNTR-TR-MGCP]

set match source-address any

set match destination-address NET-LOCAL

set match application junos-MGCP

set match application junos-MGCP-CA

set match application junos-MGCP-UA

set then permit




[EASY] How to backup a SQL Express database using SQLCMD

Posted on Updated on

Here are the steps I am doing to backup a SQL express database.  In this example, I am going to demonstrate how to backup a Skype for Business SQL express database.

Step 1:  Connect to your SQL Express Database Engine instance using SSMS.  Make sure to put the instance name.


Step 2:  Once you are connected, find the database you want to backup, right-click > Tasks > Backup


Step 3:  On the Backup Database window, make the changes you would like to make (backup type, destination, etc).  Click the drop-down for Script and select ‘Script Action to New Query Window’


Step 4:  On the new Query window, make the final changes.  You can change the path to a UNC path if you wish.  Run the script to make sure it works.

BACKUP DATABASE [lyss] TO DISK = N’\\path_to_backup_directory\lyss.bak’ WITH NOFORMAT, NOINIT, NAME = N’lyss-Full Database Backup’, SKIP, NOREWIND, NOUNLOAD, STATS = 10


If you wish to backup more databases on 1 script, repeat step 2 and select ‘Script action to Clipboard’ and put all scripts into one query window and then save it as one SQL file.

Step 5:  Save the script to a .SQL file

Step 6:  Create a scheduled task if you wish and under Actions, browse to the location of the SQLCMD file.

“C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE”

And add the arguments as:  -S \<instance name> -i <path to the SQL file you saved in step 5>


If you are not using a scheduled task.  Simply run the command:

SQLCMD -S \<instance name> -i  <path of the SQL file you saved in step 5>


“Assign Policy” option missing for Outlook users.

Posted on Updated on

I have always wondered why I was the only one in my whole organization that has the option ‘Assign Policy’ in Outlook.  I am the Exchange Engineer and administrator, but I don’t remember giving myself exclusive permissions.  Searching online also did not give me what I was looking for.


If you are like me, who searched online and did not find any answers.  Here is how I fixed this issue for regular users.

I am using Exchange 2013, to allow your users to assign their own policies, follow the steps below

  1. Login to Exchange Admin Center (EAC)
  2. Go to Permissions > User Roles and modify your default Role Assignment Policy, or whichever policy is assigned to your users.
  3. Check the box for ‘MyRetentionPolicies’ and that should give users permissions they are missing.


Shoretel IM (Instant Messenger) presence not showing in Outlook 2013

Posted on Updated on

Hi there,

I recently just reimaged my PC due to issues, and after installing Outlook 2013 and Shoretel Communicator, I noticed that my IM presence is no longer showing.

Here are the things that worked for me:

1.  Under HKCU\Software\IM Providers, the DefaultIMApp was set to Lync, and I had to change it to Communicator.  Try re-launching Outlook and see if it works.

2.  If IM presence still does not show, under HKCU\Software\IM Providers\Communicator, check and make sure the UpAndRunning value is set to 2.  You may have to toggle from 0 and back to 2.

Remove public folder user with multiple access rights

Posted on Updated on

I have come across an issue where users are assigned different permissions on public folders and I need to remove them fast.

Here is a link where I got the idea on how to go about doing it:

And here is the final script that worked for me:  Example entries for user can be “*lastname*”, “*NT USER:*” for deleted users

$test = Get-PublicFolder “\public folder\folder1” -Recurse | Get-PublicFolderClientPermission | ?{$_.User -like “*user*“} $test | ForEach {Remove-PublicFolderClientPermission -Identity $_.Identity -User $_.User -AccessRights $_.AccessRights -WhatIf}

I hope this script would help other users out there who are running into the same issue as I am.  Please leave a comment if you have any questions.