Search this blog

Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Tuesday, July 14, 2015

SQL - Get Procedure/Function/Trigger Name

Problem:
When I write any procedure for UI functionality, I may require to throw the Procedure Name to UI if any error occurs, This will help people to identify/Isolate the bug if occured
Also I Dont want to hard code the procedure name in the SPs because sometime I/someone may change the SP Name in future.
How can I prevent such a basic mistake as well as use a consistent process?

Solution:
SQL Server has a function called @@PROCID, If you use this function inside of any procedure/function/trigger, then it will return the objectid that currently running. below snippets will help you how to use this function.

Sample SP:
Create Procedure Procedure1
As
DECLARE @ProcName sysname
SET @ProcName = QUOTENAME(OBJECT_SCHEMA_NAME(@@PROCID)) +'.'+QUOTENAME(OBJECT_NAME(@@PROCID))
SELECT @ProcName

Execute SP:

Exec Procedure1

Output:
[dbo].[Procedure1]

@@PROCID Function is available from SQL 2000 onwards. This Function return Object ID, use OBJECT_NAME Function to get the Name of the Object as mentioned in the script given above.

Next Steps:
Refer the below documentation to understand complete functionality of this function as well as how to use it in different ways

MSDN: @@PROCID (Transact-SQL)
TechNet: @@PROCID

Monday, March 10, 2014

Cannot login to SSAS 2008 from SSMS?

Issue: 
When I tried to connect to a named instance of SQL Server 2008 Analysis Services (SSAS) by using SQL Server Management Studio, I received the following error message intermittently:

The 'InstanceName' instance was not found on the 'ServerName' server. (Microsoft.AnalysisServices.AdomdClient)

Solution:
 When I checked my services all the services was up & running, even I had restarted my SSAS services, but it didn't help me. but the issue was resolved after restart the SQL Server Browser service. 


If you aware, how to to restart any windows services that related SQL server then Ignore the steps below:

Steps to Restart "SQL Server Browser" service:
1.On the Start menu, right-click My Computer, and then click Manage.
2.In Computer Management, expand Services and Applications, and then click Services.
3.In the list of services, double-click SQL Server Browser.
4.In the SQL Server Browser Properties window, click Start or Stop.
5.When the service starts or stops, click OK.


After restarting the "SQL Server Browser" service, I tried to connect SSAS via SSMS, it works. Hope it may help you.

Friday, February 15, 2013

How To: Lists Linked Server

The following Stored procedure will returns the list of linked servers defined in the server in which we are executing it.

sp_linkedservers

This procedure will return the following informations about the linked server
Column name
Data type
Description
SRV_NAME
sysname
Name of the linked server.
SRV_PROVIDERNAME
nvarchar(128)
Friendly name of the OLE DB provider managing access to the specified linked server.
SRV_PRODUCT
nvarchar(128)
Product name of the linked server.
SRV_DATASOURCE
nvarchar(4000)
OLE DB data source property corresponding to the specified linked server.
SRV_PROVIDERSTRING
nvarchar(4000)
OLE DB provider string property corresponding to the linked server.
SRV_LOCATION
nvarchar(4000)
OLE DB location property corresponding to the specified linked server.
SRV_CAT
sysname
OLE DB catalog property corresponding to the specified linked server.

Or... you can use following SQL Scripts to lists all linked servers


select * from master..sysservers
Hope this helps!

Monday, July 23, 2012

E-Book Gallery for Microsoft Technologies

You can download existing and new content for ASP.NET, Office, SQL Server, Windows Azure, SharePoint Server and other Microsoft technologies in e-book formats. Reference, guide, and step-by-step information are all available. All the e-books are free




Programming Windows 8 Apps with HTML, CSS, and JavaScript (First Preview)


Happy Learning J