0
votes

I have created a Sql Server Managment Studio database, that is on Google Cloud virtual machine. Now i have C# winform app on a remote pc, and i am trying to retrive a table from that database. Virtual machine is Windows Server 2012R2 Datacenter. SSMS on virtual machine is 2014 and SQL Server 2014.

I get error in C# saying: The server was not found or was not accesible. Error 40- could not open a connection to SQL Server.

My connection string in C# is:

String strConnection=@"Data Source="Virtual machine IP"; Initial Catalog ="db 
name"; User 
ID="username";Password="password";";

Also i think i could connect to database on virtual machine, using my SSMS on my remote pc. I tried using IP address of virtual machine computer(ipconfig) and used username and password that i created in a VM SSMS. Also tried windows authetication with that ip. But everything with no succes. Error: The server was not found or was not accesible.

-I have allowed remote connections in SSMS.

-Have set SSMS login mode to mixed.

-Have set firewall exceptions on virtual machine for inbound rules, port TCP 1433, port UDP 1434, application sqlservr.exe, application sqlbrowser.exe

-On virtual machine in SQL Server Configuration Manager i have enabled TCP/IP, Named Pipes, Shared Memory

-SQL Server and SQL Browser are running on virtual machine.

If anyone has any ideas what to try next, i would be delightful.

1
A note: SSMS is the tool with which you can access and query databases (the IDE or GUI), while SQL Server is the server application itself that hosts the databases. So there is no such thing as SSMS databases, there are only SQL Server databases. Similarly, there is no SSMS login mode, only SQL Server login mode. - Peter B
If you can connect using SSMS then make your connection string the same as the one from the SSMS login window. If no password is need on SSMS remove(username and password) from the c# connection string and use Trusted_Connection=True; - jdweng
@jdweng This connection string does not work either: String strConnection= @"Server=Virtual machine IP;Database=db name;Trusted_Connection=True;"; - user2980341
Open a cmd.exe and then see if you can ping the IP >Ping Virtual_machine_IP. I assume SSMS works. Also check in SSMS using the explorer that the database existing. What error do you get with new connection string. You just said it works and didn't say it was the same error. Also the connection string must contain the server name and instance of the server like the SSMS login window. Do not leave out the instance in the connection string. - jdweng

1 Answers

0
votes

On cloud , you get the URL(connection) from the host page , not just IP address this work perfect example for AWS cloud ms sql :

add name='YOURNAMEConnectionString' connectionString=" Data Source=YOUR_ACCOUNT_LINK.rds.amazonaws.com ; Initial Catalog=;User ID=;Password=;Connect Timeout=80000 " providerName="System.Data.SqlClient"