Sunday 21 April 2024

Understanding SQL Server Endpoint Types

A SQL Server endpoint is essentially a communication port that allows different systems or applications to interact with the SQL Server database engine. It acts as a gateway, facilitating communication between the SQL Server instance and external entities,

SQL Server supports various endpoint types, each designed to accommodate specific communication protocols and requirements.
These can be broadly categorized into two types: system-defined endpoints and user-defined endpoints.

System-Defined Endpoints
System-defined endpoints are preconfigured by SQL Server and are integral to its functionality. They include:
SELECT * FROM sys.endpoints;    

User-Defined Endpoints
User-defined endpoints are created and configured by database administrators or developers to serve specific requirements. They include:

TSQL Endpoint: Allows remote connections for executing Transact-SQL commands against the SQL Server instance.
HTTP Endpoint: Facilitates communication using HTTP/HTTPS protocols, often utilized for web services integration.

Creating TSQL Endpoints:
Enable TCP/IP Protocol: Ensure TCP/IP protocol is enabled for SQL Server.
EXEC sp_configure 'remote access', 1;
RECONFIGURE;
 

Use the CREATE ENDPOINT statement to create a TSQL endpoint.
CREATE ENDPOINT [MyTsqlEndpoint]
STATE = STARTED
AS TCP (LISTENER_PORT = 1433)
FOR TSQL();
 

Grant necessary permissions to the endpoint.

GRANT CONNECT ON ENDPOINT::[MyTsqlEndpoint] TO [YourUser];

Creating an HTTP Endpoint:
Enable HTTP Protocol: Enable the HTTP protocol for SQL Server.

EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;

Use the CREATE ENDPOINT statement to create an HTTP endpoint.
CREATE ENDPOINT [MyHttpEndpoint]
STATE = STARTED
AS HTTP (
   PATH = '/MyService',
   AUTHENTICATION = (BASIC),
   PORTS = (CLEAR),
   SITE = 'localhost'
);

 

Grant necessary permissions to the endpoint.
 GRANT CONNECT ON ENDPOINT::[MyHttpEndpoint] TO [YourUser];

Managing Endpoint State
Endpoints can be in one of three states: STARTED, STOPPED, or DISABLED. Here's how you can manage endpoint states:

    STARTED: Endpoint is active and accepting connections.
    STOPPED: Endpoint is inactive but can be started.
    DISABLED: Endpoint is inactive and cannot be started.

Change the state of an endpoint: use the ALTER ENDPOINT statement:
ALTER ENDPOINT [MyEndpoint] STATE = STOPPED;

 

Thursday 7 March 2024

USE statement is not supported to switch between databases. Use a new connection to connect to a different database.

This issue occurs because Azure Managed Instance and Azure SQL Database does not support the "use" command. 

Workaround:

To work around this issue, select the correct database first in the SSMS database drop-down list, and then execute the stored procedure.

 

Thursday 29 February 2024

SQL Query to Find Client(session) Oracle Driver Version

select SID, AUTHENTICATION_TYPE, CLIENT_VERSION, CLIENT_DRIVER from v$session_connect_info;
SID   AUTHENTICATION_TYPE CLIENT_VERSION CLIENT_DRIVER

----- ------------------- -------------- ---------------
2046  DATABASE            21.9.0.0.0 jdbcthin : 21.9.0.0.0
2049  DATABASE            21.9.0.0.0 jdbcthin : 21.9.0.0.0
2055  DATABASE            21.9.0.0.0 jdbcthin : 21.9.0.0.0
4875  DATABASE            21.9.0.0.0 jdbcthin : 21.9.0.0.0
14937 DATABASE            21.9.0.0.0 jdbcthin : 21.9.0.0.0


Use below query to find application user and client machine
select ses.username,ses.machine,driv.CLIENT_DRIVER,driv.CLIENT_VERSION from gv$session ses , gv$session_connect_info driv where ses.sid=driv.sid;


Tuesday 6 February 2024

Changing Sql Server Compatibility Level

The compatibility level for a database can be changed very easily using the ALTER DATABASE statement. Here is the basic syntax:

ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = version;

For example, to change a database named ‘devdb’ to the SQL Server 2022 compatibility level:

ALTER DATABASE devdb SET COMPATIBILITY_LEVEL = 160;