Link to home
Start Free TrialLog in
Avatar of ISIGest
ISIGestFlag for Italy

asked on

Current Listening SQL Server 2008 TCP/IP Port Delphi

How i can set the TCP/IP listening port for SQL Server Express 2008 programmatelly??
Avatar of ISIGest
ISIGest
Flag of Italy image

ASKER

I run a Vista Businnes 64bit and i've been installed a SQL Server 2008 64bit version and a SQL Server 2005 32bit.
When i try access to a registry key value:
SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL
the result of existing key value is only SQL2005 becouse it access to:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL
How i can access to a 64bit (Standard) key values?
const
  INSTANCE_KEY = 'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL';
  KEY_VALUES = 'SOFTWARE\Microsoft\Microsoft SQL Server\%s\MSSQLServer\SuperSocketNetLib\Tcp\IPAll';
var
  LValue: string;
  LReg: TRegistry;
begin
 
  LReg := TRegistry.Create;
  try
    with LReg do begin
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKeyReadOnly(INSTANCE_KEY) then begin
        if ValueExists(SQLSERVEREXPRESS_ISTANZA_DEFAULT) then
          LValue := ReadString(SQLSERVEREXPRESS_ISTANZA_DEFAULT);
 
        CloseKey;
 
        if not Empty(LValue) then begin
          if OpenKey(Format(KEY_VALUES, [LValue]), False) then begin
            WriteString('TcpDynamicPorts', EmptyStr);
            WriteString('TcpPort', IntToStr(SQLSERVEREXPRESS_PORTA_DEFAULT));
            CloseKey;
          end;
        end
        else begin
          // ERROR
 
        end;
      end;
    end;
  finally
    LReg.Free;
  end;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial