SSMS ISSUE: Connection information does not change in SSMS when a new Query is created from Dedicated Administrator Connection

Description:
Connection information does not change in SQL Server Management Studio for SQL Server 2008 r2 when a new Query is created from Dedicated Administrator Connection.

Steps:
1. Open SQL Server management studio and connect to SQL Server in Dedicated Administrator Connection.
In order to connect to SQL Server in Dedicated Administrator Connection (DAC) you have to add ADMIN: before the SERVER\INSTANCE name.

Dedicated Administrator Connection

2. After connecting the the Server with DAC click on new query.

3. You will get the error that you cannot connect as you are already connected to the server with DAC and only one DAC Connection is allowed.

[text]
TITLE: Connect to Database Engine
——————————

Cannot connect to ADMIN:..

——————————
ADDITIONAL INFORMATION:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 – An established connection was aborted by the software in your host machine.) (Microsoft SQL Server, Error: 10053)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=10053&LinkId=20476

——————————
BUTTONS:

OK
——————————
[/text]

4. Now in the error message popup click OK and change the connection to any other SQL Server.

5. Now you will find that the connection details displayed when you keep the mouse pointer over the SQL Server Query are still showing that of the DAC.

BUG SSMS DAC

SSMS Available Databases DropDown Acts weird if Connection Properties Are Changed

SQL Server Management Studio (SSMS) Has a available databases dropdown ( to select a database to execute the query.).

Available Databases Dropdown in SSMS

This dropdown behaves weird when you change the connection properties.

Observation 1:
Run the below query in the query window
[sql]
SET PARSEONLY ON
[/sql]

Now when you try to expand the dropdown, the drop down does not expand.

Run the below query to turn off PARSEONLY
[sql]
SET PARSEONLY OFF
[/sql]

Observation 2:

Run the below query in the query window
[sql]
SET ROWCOUNT 2
[/sql]

Now if you try to click on the dropdown, you will find only 2 available databases.

Run the below query to reset ROWCOUNT to 0
[sql]
SET ROWCOUNT 0
[/sql]

Why is the dropdown behaving this way?
SSMS is using the same connection used by the query to fetch the Available databases list.
SSMS runs the below command to fetch the results for the Availabale Databases DropDown, using the same connection used by the Query.
[sql]
SELECT dtb.name AS [Name], dtb.state AS [State] FROM master.sys.databases dtb
[/sql]

Also, You would also get wrong results count into the @@ROWCOUNT, when you run the query and accidentally touch the availabale databases dropdown.

Observation 3:
Run the below query
[sql]
SELECT * FROM SYS.OBJECTS
SELECT @@ROWCOUNT as ROWSCOUNT
[/sql]
Make a note of the ROWSCOUNT Result.

Now run the query
[sql]
SELECT * FROM SYS.OBJECTS
[/sql]

Click on the available databases dropdown and run the below query.

[sql]
SELECT @@ROWCOUNT as ROWSCOUNT
[/sql]

You can identify the difference in the values of @@ROWCOUNT.

The first result would be the number of objects in the database.
The second result would be the number of databases in the Server.

sql server does not exist or access denied sql server 2008 r2

Following are some of the Steps to resolve this error:

1) Check if user has access to the server/database
2) Check if the users passowrd is updated, If so use the latest password.
2) Check if the server name is correct
3) Check if the SQL Server service is running
4) Configure Log On As in services.msc if this error is occuring while connecting to systems across the network. Change the log on account and check if the error is fixed.

sql server 2008 r2 edition upgrade failed

When you upgrade for sql server 2008 r2, you would get an error:

Rule sql server 2008 r2 feature upgrade failed the specified edition upgrade is not supported

In such a case check if your version upgrade is supoorted in the below link:

Version and Edition Upgrades SQL Server 2008 R2

You can also download SQL Server 2008 R2 Upgrade Advisor from the below links:

X86

X64

IA64

install sql server management studio 2008 windows 7

If you try to install sql server management studio 2008 (ssms) on your windows 7 system you could face a few problems installing it.

Following are some of the simple steps that could help you solve the problem:

Step 1:
Remove any versions of SQL Server 2008 installed in the system

Step 2:
Download SQL Server 2008 Express with tools from one of below link:
Microsoft® SQL Server® 2008 Express with Tools
OR
Microsoft SQL Server 2008 R2 RTM – Management Studio Express

Install the downloaded file (Run as Administrator)

Step 3:
Upgrade you sql server version using the below link:
How to obtain the latest service pack for SQL Server 2008

Why is SQL Server consuming Lot of RAM

Why is SQL Server consuming Lot of RAM

There could be multiple reasons why SQL Server is consuming lot of physical memory (RAM).

Following are the few that I would like to list out:

1) Performance of the server could be bad as the queries that are hitting the sever are not optimal.
You can further fine tune such queries.

2) Maximum and Minimum server memory configuration is not set up properly.
You can set up maximum server memory configuration so that it doesnt eat up whole of the RAM.

Following are the Steps to configure sql server memory allocation:

  • Connect to the SQL Server in SQL Server management studio
  • Right click on the server and click on properties
  • Now the Server Properties window pops up.
    In the Server Properties window Select Memory.
    Now check the values of
    Minimum Server Memory(in MB) and Maximum Server Memory(in MB)

    Configure Maximum And Minimum SQL Server Memory
    Configure Maximum And Minimum SQL Server Memory
  • Adjust these values to opimal memory values as per your SQL Server’s memory requirement.

Note: Be aware that changing the memory configuration of SQL Server might give you very bad results. Hence be cautious before making such changes.
You might also get There is insufficient system memory in resource pool ‘default’ to run this query error if memory configuration is bad.

Incorrect syntax was encountered while parsing GO.

When you try to execute the code which has multiline comment after GO statement you get the error:

A fatal scripting error occurred.
Incorrect syntax was encountered while parsing GO.

Following piece of code can be used to reproduce this error:

Try parsing this SQL Code:
[sql]
SELECT ‘A’
GO /*Completed the batch*/
[/sql]

The code looks perfectly fine but when you parse it you get the fatal error shown above. 🙁

Now try parsing this piece of code:
[sql]
SELECT ‘A’
GO –Completed the batch
[/sql]

This code parses successfully. 🙂

You get same error when you parse the below code:
[sql]
SELECT ‘A’ SELECT ‘B’
GO SELECT ‘C’
[/sql]

The code given below works fine, it runs the select statements in the batch for 4 times.
[sql]
SELECT ‘A’ SELECT ‘B’
GO 4
[/sql]

But this code fails while parsing:
[sql]
SELECT ‘A’ SELECT ‘B’
GO 4 /*Execute the batch times%
[/sql]

So in general(not completely sure) SQL Parser is giving error when GO statement has some text following it(except — or a number)

Alternate Fix:

Use single line comments(–) instead of multiline comments(/**/) after the GO statement

This error is logged with microsoft in the following link: Microsoft link

SQL Server Peculiar Issue – Error Converting Varchar to Bigint

Yesterday I had a chat with one of my friend who was having problem with his SQL Query.
Ill just list down his Peculiar problem and the way we solved it in this blog post. It would be a good learning to all.

The problem he had:
– There was an insert script for a table(say it tablex).
– All the columns in this table were of type varchar(100).
This insert script was running fine for most of the insert values, but was failing when one of the column has value ‘123E99’.
– The error the script was giving was:

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to bigint.

All the columns being varchar, why was this error occuring?
Why is this datatype conversion happening?
Is this conversion implicitly happening or it explicitly done?
Why was this error occuring only for value ‘123E99’ but not for value ‘128M99’?

Following are the steps we followed to find the reason for this error:
Checked the table definition to see if there were any triggers on the table.
There were no triggers on this table

Analysed the input value which was giving the error.
‘123E99’ – This value has E as part of it.
When the below query is executed it gives 1 as output.
[sql]
SELECT isnumeric(‘123E99’);
[/sql]

But the output will be 0 for ‘128M99’.
This means sql server understands ‘123E99’ as a numeric value but not ‘128M99’.

So there is some part of code somewhere in the database which is causing this issue by validating weather the value is numeric.

So we went ahead and searched for all the indexed views in the database.
We found one that is using this table.

Below is the piece of code in this indexed view
[sql]
CASE WHEN ISNUMERIC(tablex.column2) = 1
THEN CONVERT(BIGINT,tablex.column2)
[/sql]

So this is the code that is giving the above error.
The ISNUMERIC is giving true but conversion to big int is failing as the value is larger that that of bigint.
Modifying this piece of code solved the issue. 🙂

Why was this indexed view code running when he was executing the insert script on tablex?

Just Because tablex is being used in the indexed view, indexed view has to be indexed with new data in tablex

Learnings form this post:
When you face such peculiar issues of conversion etc..

  • check for the design of the table and see if the conversion is implicitly happening.
  • Check for the triggers on the table, and see if there is any implicit or explicit datatype conversion happening there.
  • Check for the indexed views in the database, See if there is any implicit or explicit datatype conversion in the indexed views.

Cannot open object explorer in SSMS

Problem:
When you try to open object explorer in SQL Server management studio object explorer does not come up.

Fix:
Reset the window layout.
To reset the lay out in SQL Server Management Studio, Select Window Menu and Select Reset Window Layout Option

  • Window > Reset Window Layout
    Reset Window Layout

This should fix the issue.

Additional Problem details:
All the options of opening object explorer will be unsuccessful and object explorer does not show up.
using menu view > object explorer
using F8 Shortcut key

Even if SSMS is reopened object explorer does not show up, also after restarting the system object explorer is not visible.