0

So I'm running an SQL Server on my home computer [THOR].

I have a program that boots up, and then lists the SQL servers it can find.

I'm using a code called "SQLInfoEnumerator" which I found on another forum.

  • I don't believe that is the issue so i haven't put that code here.

On the server (THOR) it lists (local) asthe only server (which is correct)

So I use this listed item and insert it into this string:

string lotsconstring = "Data Source=" + SQLServer + ";Database=" + "lots" + ";Integrated Security=False;User ID=sa;Password=XXXXXXX";

Now when i run it on my home computer it works, and the connection is established.

When I run it on a laptop which is connected via WIFI, it finds:

\\THOR\SQLEXPRESS

and the connection fails.

Now to test the idea that this does work in other cases, i installed my program is a business owned by a friend.

Master = "SERVER"

And it finds: \\SERVER\SQLEXPRESS

and the connection WORKS!

So in conclusion;

Program finds list List entry works for my server List entry works for a client connecting to a server in a real business network List entry DOESNT work for a client PC on my home network connecting to the server..

Anything I can try or tests to find out why the connection doesn't work?

EDIT:

Also, I have just tried on both home server and the laptop just having "Data Source = THOR" and it works!

So home: Just the PC name works, having the instance fails At work: Having the PC name fails and having the instance there works!

EDIT 2: Exception code from the failed connection (trying to con.open())

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

As mentioned, if i just use THOR not \\THOR\SQLEXPRESS it works, so it shouldnt be a matter of not allowing a remote connection

Testing: THOR = Works on both

THOR\SQLEXPRESS = Fails on Laptop

THOR\\SQLEXPRESS = fails on both

I'm also using @ at the front of the strings.enter image description here enter image description here

Glenn Angel
  • 381
  • 1
  • 3
  • 14
  • Are you sure that the required programs to connect to MS SQL are properly installed on the laptop unit? – jegtugado Oct 13 '17 at 06:19
  • Hi john, Thnks for the response. Yes i have been connecting just using "THOR" and not the SQLEXPRESS part. When i installed it on a work computer and it failed with just Server name, thats when i created this instance finder part... Ive edited the above post and explained further – Glenn Angel Oct 13 '17 at 06:21
  • What do you mean by it doesn't work? Can't you simply create a text file log containing the exception details you are getting? I assume that your program is failing on the connection open part. – jegtugado Oct 13 '17 at 06:26
  • Sorry John, I should have started with that. Exception code added into edit – Glenn Angel Oct 13 '17 at 06:29
  • check your Firewall IF It's ON Turn IT OFF and check – Alfaiz Ahmed Oct 13 '17 at 06:32
  • There are different cases for that generic exception. You can look at this post https://stackoverflow.com/questions/1391503/why-did-a-network-related-or-instance-specific-error-occur-while-establishing-a for possible solutions. – jegtugado Oct 13 '17 at 06:41
  • Thanks I'l have a look. Alfiaz, would the firewall affect that if it works with just computer name? – Glenn Angel Oct 13 '17 at 06:42
  • The double backslash \\ before the servername is [superfluous](https://www.connectionstrings.com/sql-server/) and maybe the main-problem. – MatSnow Oct 13 '17 at 06:52
  • Besides you have to [escape the backslash](https://stackoverflow.com/questions/10542565/how-to-pass-connection-string-that-has-a-backward-slash-to-sqlconnection) if servername is like `SERVER\INSTANCE`. – MatSnow Oct 13 '17 at 06:56
  • thanks Mat. Tried and no luck! Pretty much for some rason, having the instance there is just casuing issues for the networked computer. No isssue for the actual server computer – Glenn Angel Oct 13 '17 at 07:11
  • Is there a SQLEXPRESS-instance on your (THOR) computer at all? – MatSnow Oct 13 '17 at 07:12
  • Well doesnt there have to be if i can connect to it and use it if i just use the computer name? Its there in SQL manger "THOR\SQLEXPRESS" and if i use THOR only in the con string it works fine and i can update stuff and my program runs perfectly – Glenn Angel Oct 13 '17 at 07:18
  • Most likely there are two instances on the PC. The default-instance `THOR` and the `THOR\SQLEXPRESS`. The default-instance has TCP/IP enabled and is allowed on the firewall, the sqlexpress has TCP/IP disabled and/or is not allowed on the firewall. You can check this in [SQL Server Configuration Manager](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-configuration-manager) – MatSnow Oct 13 '17 at 07:40
  • Thanks for the help MatSnow.. I'm sure you are on to it but still can't get it working. I've gone to Config manager and can only see one instance in "SQL Server Netowrk Configuration" Which is "Protocols for SQLEXPRESS" However If i go into SQL server mangement and instead of connecting to THor\SQLSERVER I just connect to THOR, i manage to get a second connection running... Soooo I think you are right but I can't see where this "THOR" only instance has come from!? – Glenn Angel Oct 13 '17 at 07:50
  • Ok so inside Server Manager In Properties\View COnnection properties: 1. Server Name = THOR Instance Name = SQLEXPRESS 2. Server name = THOR\SQLEXPRESS Instance name: SQLEXPRESS So it actually looks like the server NAME is THOR\SQLExpress which is weird!? – Glenn Angel Oct 13 '17 at 07:53
  • added screen shots.. – Glenn Angel Oct 13 '17 at 08:23
  • Is there something configured inside the `Aliases`-section? – MatSnow Oct 13 '17 at 08:38
  • Hi Matt, no, there is nothing in any of the aliase sections – Glenn Angel Oct 13 '17 at 09:25
  • I'm not sure why you even can connect without serving the instance-name if there's no alias. But i've seen now on the printscreen that the [SQL Server Browser](https://learn.microsoft.com/en-us/sql/tools/configuration-manager/sql-server-browser-service)-service isn't started. Start it and test again. It is needed to find the instance when connecting from remote. – MatSnow Oct 13 '17 at 09:46

0 Answers0