-1

I was wondering if someone could help me with this problem I have? I am not able to connect to my SQL server even though I correctly provided my IDE with the SQL server's port number and my IP address.

 static SqlConnection connection = new SqlConnection(@"Data Source=192.168.1.198,49172;Initial Catalog=irradix_base;Integrated Security=False;User ID=sa;Password=pass;");
Epic
  • 1
  • 4
  • usually a firewall prevents connections from the Lan, did you open them? – nbk Apr 30 '22 at 20:33
  • What have you done so far? What is the currently set static port of the instance? You need to set the static port to `49172` (or change your connection string to match the port being used). You need to enable Remote Connections and TCP. You need to create a firewall exception for `sqlservr.exe` – Charlieface May 01 '22 at 11:10
  • I did set the static port to 49172. I did not create a firewall exception for sqlservr.exe though. I will do that now. – Epic May 01 '22 at 14:50

2 Answers2

0

Can you try this way Data Source=192.168.1.198,49172;Initial Catalog=EnVerifyDB;User ID=sa;Password=123456

Bayram Eren
  • 422
  • 4
  • 6
  • This is not what I am asking for. The “Initial Catalog” is to verify which database in my server that I am using. Changing the database will not help with my problem. – Epic May 01 '22 at 14:52
0

So as it turns out, I found an answer from this post which uses a powershell command to find the listening port, here is the code:

ForEach ($SQL_Proc in Get-Process | Select-Object -Property  ProcessName, Id | Where-Object {$_.ProcessName -like "*SQL*"})
{
    Get-NetTCPConnection | `
     Where-Object {$_.OwningProcess -eq $SQL_Proc.id} | `
      Select-Object -Property `
                                @{Label ="Process_Name" e={$SQL_Proc.ProcessName}}, `
                                @{Label ="Local_Address";e={$_.LocalAddress + ":" + $_.LocalPort }},  `
                                @{Label ="Remote_Address";e={$_.RemoteAddress + ":" + $_.RemotePort}}, State | `
      Format-Table
} 
user2816085
  • 655
  • 4
  • 19
Epic
  • 1
  • 4