Objective: You have a .sql file you wish to import in Microsoft SQL Server (MSSQL)
Solution: Microsoft has a command line utility called Sqlcmd that can be used to import very large datasets into SQL server without having to open the file. More information on this utility can be found here: http://msdn.microsoft.com/en-us/library/ms162773.aspx
Here is a snippit of the utility and its available switches before beginning:
usage: Sqlcmd [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend] [-L[c] list servers[clean output]]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile] [-z new password]
[-f | i:[,o:]] [-Z new password and exit]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-v var = "value"...] [-A dedicated admin connection]
[-X disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]
Here is an example of how to use the utility:
- Open up a command prompt
- Note: Administrative privileges are optional depending on how you have your security settings configured.
- Execute the following command
- sqlcmd -S SERVERNAME\INSTANCE_NAME -i C:\path\mysqlfile.sql
- Here are some notes/tricks you might want to use:
- If you are using the default instance when you installed MSSQL server, you don't have to specify \INSTANCE_NAME
- You can log results to a text file by appending the following switch: -o C:\path\results.txt
- You can specify a database to import to by appending the following switch: -d MYDATABASE
- You can specify username and password by appending the following switch: -u USERNAME -p PASSWORD
--Note: You can wait to be prompted for credentials by optionally leaving out the -p switch, however if you are piping the results out to notepad, the command will not fully execute.
Symptom: When restoring a database in Microsoft SQL Server Management Studio, you receive the following dialog box similar to something below:
Restore failed for Server 'myserver'. (Microsoft SqlServer.SmoExtended)
System.Data.SqlClient.SqlError: File 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mydatabase.mdf' is claimed by 'mydatabase_FG1'(3) and 'mydatabase'(1). The WITH MOVE clause can be used to relocate one or more files. (Microsoft.SqlServer.Smo)
Solution: On the Restore Database - mydatabase window inside of Microsoft SQL Server Management Studio:
- Click on the Options page.
- Underneath Restore the database files as: label, make sure all of the "Restore As" values are unique. In this case, I renamed each *.mdf file to it's "Original File Name" column value.
- Click OK
Viola! Your database should now successfully restore 🙂
Symptom: You receive the following error when trying to drop an orphaned user from a msSQL database.
The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15421)
Solution: Follow the steps below:
- Open up Microsoft SQL Server Management Studio
- Start->All Programs->Microsoft SQL Server 2008 R2->SQL Server Management Studio
- Navigate to the database that you cannot drop the user from.
- Expand the Security section inside of the database
- Expand the Users section and right click on the user and rename it (to something other than the new user... assuming you are trying to use a new login with the same username)
- Expand the Roles section underneeth the Security section
- Expand the Database Roles section
- For each Database Role, Right click->Properties on a role and ensure the Owner attribute is set to the new account you wish to use
- Once you have removed all references to the orphaned account inside of the Owner attributes, you should be able to remove the user from the database.
Symptom: You receive the following error when browsing to the following page in the Reports Viewer: https://mymachine.mydomain/ReportServer/Pages/ReportViewer.aspx?%2fLyncServerReports%2fReports+Home+Page&rs:Command=Render Alternatively, you receive this error when you go to https://mymachine.mydomain.com/Reports/ and click on LyncServerReports and then Reports Home Page.
Note: the solution below applies to the QMSDB as well.
- An error has occurred during report processing. (rsProcessingAborted)
- Cannot impersonate user for data source 'CDRDB'. (rsErrorImpersonatingUser)
- Log on failed. Ensure the user name and password are correct. (rsLogonFailed)
- For more information about this error navigate to the report server on the local server machine, or enable remote errors
Solution: For whatever reason, my service account I created actually had the incorrect password to login to the 'CDRDB' data source. To fix/troubleshoot this, follow the steps below:
- Head over to https://myserver.mydomain/Reports (myserver being the server with the reporting services on it)
- Click on LyncServerReports
- Click on Reports_Content
- Click on CDRDB
- Under Credentials stored securely in the report server, type in the username/password are want to use to connect to the SQL server, and then click the Test Connection button. If you should see a Connection created successfully. message, you are good to go. If you see a Log on failed. Ensure the user name and password are correct. message, ensure that the account you setup has the correct username/password in active directory, is Unlocked in Active Directory (due to bad password attempts), and that it has permissions to the databases mentioned in the Connection string on the same page.
Scenario: You have accidentally installed SQL Server 2008 R2 Workgroup and you need SQL Server 2008 R2 Standard. Obviously, you don't want to rebuild your server from the ground up and have extended downtime, so an upgrade option would be sweet. Luckily, Microsoft has come to the rescue with an easy way to update your msSQL server/instances.
Solution: Go to the Microsoft Licensing center or grab your SQL Server disk/installation media of the correct version. I.e. if I was running standard, I would grab the enterprise disk to upgrade. Once you have the disk, follow these steps:
- Find your installation media and double click on Setup.exe
- When the SQL Server Installation Center window comes up, click on Maintenance
- Click on Edition Upgrade
- On the SQL Server 2008 R2 Setup - Setup Support Rules window, click OK
- Click Next > on the Upgrade the Edition for SQL Server 2008 R2 window
- Click Next > on the Enter a product key: page.
- Click I accept the license terms. and then click Next >
- Select the instance of the SQL Server you wish to upgrade and then click Next >
- Click Next >
- Click Upgrade
To verify your SQL Server upgraded, follow this guide here to pull your msSQL version: http://jackstromberg.com/2013/01/how-do-i-find-out-if-my-sql-server-is-32-bit-or-64-bit/
Want to know what version of SQL server your have running? All we need to do is execute one SQL command and away we go 🙂
- Go to your SQL server
- Open up the Microsoft SQL Server Management Studio
- Start->All programs->Microsoft SQL Server 2008 R2->SQL Server Management Studio
- Login with your user
- Click the New Query button
- Execute the following query
- SELECT SERVERPROPERTY('edition')
Symptom: When installing the Monitoring Agent for Lync 2010, I was receiving the following information in the "log" file:
> Deploying Monitoring Server Reports... This might take a few minutes.
The Monitoring Server is using SQL instance "myserver.mydomain".
The data source is using SQL instance "(local)".
The following URL will be used for deployment: https://myserver.mydomain:443/ReportServer
SQL Server logon credentials for "mydomain\myuser" already exist. Use the existing logon credentials.
"[QoEMetrics]" role "[ReportsReadOnlyRole]" has already assigned to "mydomain\myuser".
"[LcsCDR]" role "[ReportsReadOnlyRole]" has already assigned to "mydomain\myuser".
Start to deploy reports...
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
An error occurred when deploying Monitoring Server Reports. For details, see the log.
Turns out this was because I had accidentally forgot to add in the common name to my SSL certificate as a SAN address. Bottom line, the issue is that your SSL certificate is bad.
- Request a new SSL certificate
- Add in the Certificates snap-in
- Select Local Computer
- Expand Certificates->Personal->Certificates
- Right click, All Tasks->Request new Certificate...
- Select your policy
- Enter in the information you would like. Note, if you are adding a SAN address for the short name, make sure you add both the FQDN and the short name as DNS entries in the Alternative name box.
- Click on the Private Key tab, expand the little arrow and check Make private key exportable
- Click OK
- Click Enroll
- Click Start->All Programs->Microsoft SQL Server 2008 R2->Configuration Tools->Reporting Services Configuration Manager.
- Click Connect
- Click Web Service URL
- Under SSL Certificate, select the appropriate certificate and click Apply
- At this point, you either saw a bunch of green check marks and you are good to go, or else you probably hit the dreaded "rouge SSL cert" error. To fix that, please see this link: http://jackstromberg.com/2013/01/sql-server-2008-r2-reporting-services-configuration-manager-create-certificate-binding-failed-hresult-0x80040238/
Symptom: When changing an SSL certificate inside of the SQL Server 2008 R2 Reporting Services Configuration Manager, you receive the following error:
Create certificate binding.
When you click on "Tell me more about the problem and how to resovle it." you receive the following:
Microsoft.ReportingServices.WmiProvider.WMIProviderException: An SSL binding already exists for the specified IP address and port combination. The existing binding uses a different certificate from the current request. Only one certificate can be used for each IP address and port combination. To correct the problem, either use the same certificate as the existing binding, or remove the existing SSL binding and create a new binding using the certificate of the current request.
---> System.Runtime.InteropServices.COMException (0x80040238): Exception from HRESULT: 0x80040238
--- End of inner exception stack trace ---
at Microsoft.ReportingServices.WmiProvider.RSWmiAdmin.ThrowOnError(ManagementBaseObject mo)
at Microsoft.ReportingServices.WmiProvider.RSWmiAdmin.CreateSSLCertificateBinding(String application, String certificateHash, String ipAddress, Int32 port)
at ReportServicesConfigUI.WMIProvider.RSReportServerAdmin.CreateSSLCertificateBinding(UrlApplication app, String certificateHash, String ipAddress, Int32 port)
This error really sucks and the reason behind it is that Microsoft just didn't do a good job removing/unbinding SSL certificates from an interface. Luckily, I have the solution to get you up and going...
- Download the Windows Server 2003 Support Tools from Microsoft
- Install the tools on your local machine or on the server. You may get a warning about incompatibility if you install it on your Windows 7 machine. I ignored this and things seem to work fine 😛 Just note if you do this, you will need to copy the following folder from your local machine to the server with SQL Server Reporting Services Configuration Manager: C:\Program Files (x86)\Support Tools
- Open up a command prompt with Administrator privileges on the server with SQL Server 2008 R2 Reporting Services Configuration Manager
- Navigate to the following directory (if you copied the folder from your local machine, browse to the appropriate directory you copied the support tools to):
- cd "C:\Program Files (x86)\Support Tools"
- Launch SQL Server 2008 R2 Reporting Services Configuration Manager
- Start->All Programs->Microsoft SQL Server 2008 R2->Configuration Tools->
Reporting Services Configuration Manager
- Click on Web Service URL
- Click on the Advanced... button
- Remove any items listed inside of the "Multiple SSL Identities for the Report Server Web Service" box.
- Click OK
- Go back to your command prompt with the Administrator privileges and execute the following commands to unbind the old SSL certificate
- netsh http delete sslcert ipport=[::]:443
- You should see something like "SSL Certificate successfully deleted" -- If not, that is fine
- httpcfg delete ssl /i 0.0.0.0:443
- You should see something like "HttpDeleteServiceConfiguration completed with 0." -- If not, that is fine as long as the command above said it removed a certificate
- Go back to the Reporting Services Configuration Manager and select your SSL certificate in the SSL Certificate dropdown.
- Click Apply
At this point, your certificate should have bound to the interface successfully.
Hope this helps someone!
Want to encrypt your msSQL traffic? Here is how to do it.
- Request/Install a certificate in the Windows Certificate store
- If you are on a domain with a certificate authority, you can do this by clicking Start->run->mmc
- Click File->Add/Remove Snap-in
- Select Certificates, click the Add button, select Computer account, click OK, click Finish the wizard.
- Expand Certificates (Local Computer) and navigate to Personal->Certificates
- Right click All Tasks -> Import... or Request New Certificate (depending on what you want to do)
- Once you have finished installing the certificate, click Start->All Programs->Microsoft SQL Server 2008 R2->Configuration Tools->SQL Server Configuration Manager (Launch SQL Server Configuration Manager)
- Expand SQL Server Network Configuration
- Right click on "Protocols for MSSQLSERVER" (or whatever your instance name is on the left side) and click Properties
- On the Flags tab, you can optionally set "Force Encyrption" to Yes, which will make your msSQL server only allow connections that are secure. You may skip this step if you don't want to do this.
- Click on the Certificate tab.
- Select your certificate that you installed in Step 1 in the Certificate dropdown box.
- Click OK
- Click on SQL Server Services
- Right click on the SQL Server (MSSQLSERVER) service and click Restart (MSSQLSERVER==your instance name)
That's all that's to it. Note, if you receive an error that the service cannot run (I forgot what the original error was), try disabling the VIA Client Protocol underneath SQL Native Client 10.0 Configuration inside of SQL Server Configuration Manager.
As a reference, you can find the official Microsoft KB article on how to do this here.
If you are trying to login to a SQL server and you are receiving just the generic 18456 error, here is how to figure out what is going on.
- Open up the Microsoft SQL Server Management Studio tool.
- Login with an account that has administrative privileges.
- Click on Security and make sure under "Login Auditing" you have at least Failed logins only checked or higher.
- Click OK.
- Try to login with your account on another server to trigger the 18456 Error
- Go back to the SQL Server and open up Event Viewer (Start->Administrative Tools->Event Viewer)
- Click on Windows Logs->Application
- You should see Event ID 18456 inside of your logs (It won't be Critical or Error level, just Information).
- Double click on your event, and it should give you some information on why the account is unable to login.
For example, in my case, I was attempting to use SQL authentication on the server, and the log told me the server was only setup for Windows Authentication (sure enough, it was! :P).
Hope this helps!