-1

i have SQL server express 2012 installed on windows 10 64 bit, the connection from same computer worked fine, problem when i connect from another computer on same network, i get error message:

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 connection
-provider TCP provider error 0 the wait operation timeout

i try the following things but not fix the problem:

  • Enable and automaticly start SQL Browser
  • Enbale TCP/IP and set port 1433 for all IP types
  • Start Named inslance SQLExpress2012 autmaticaly as Build-in : Network service
  • connect without user and password with IntegratedSecurity=true
  • The database is using mixed-mode authentication
  • add an exception in the firewall for port 1433
  • enable named pipe
  • allow remote connection

this is my code:

        public static bool TestSQLServerConnection(
            string ComputerNameOrIPAddress,
            string SQLServerInstanceName,
            string PortNumber)
        {

            try
            {
                
                SqlConnectionStringBuilder SQLServerConnectionString = new SqlConnectionStringBuilder();
                SQLServerConnectionString.DataSource = ComputerNameOrIPAddress+",+"+PortNumber+"\\"+SQLServerInstanceName;
                SQLServerConnectionString.InitialCatalog = DatabseName;
                SQLServerConnectionString.TrustServerCertificate = true;
                SQLServerConnectionString.IntegratedSecurity = true;
                
                //SQLServerConnectionString.UserID = "...";
                //SQLServerConnectionString.NetworkLibrary = "DBMSSOCN";
                //SQLServerConnectionString.Password = "...";

                SqlConnection con = new SqlConnection(SQLServerConnectionString.ConnectionString);
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText=  "select 1";
                con.Open();
                cmd.ExecuteScalar();

                con.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

when i ping the ip address or computer name of computer of SQL Server it connected and return response, means the computer is connected to network. i search for while without any solution, please help me.Thanks

jarlh
  • 42,561
  • 8
  • 45
  • 63
Fath Bakri
  • 161
  • 1
  • 12
  • Is the browser service on the host also running? You say that the instance is called `SQLExpress2012`; the default name for an express instance is `EXPRESS`, so I assume you've chosen to use a different name? Also, side question, why 2012? Express is free, and 2012's is pretty close to end of extended support; there's several newer versions that have full support. – Thom A Jan 13 '21 at 09:47
  • SQL Browser uses 1434 also – Charlieface Jan 13 '21 at 09:56
  • i use sql server 2012 Express , because i have windows 32 bit and from sql server 2014 and newer it only work on win 64 bit – Fath Bakri Jan 13 '21 at 11:37
  • yes i start SQL Browser service automatically – Fath Bakri Jan 13 '21 at 11:40
  • i install SQL Server management studio on another computer and try to connect to SQL server in remote computer, it connected but i cannot see my database in database engine, and i still cannot connect to SQL server vi my code mentioned above. – Fath Bakri Jan 13 '21 at 11:58
  • why i can connect from sql server management studio to remote sql server but i cannot see my database in database engine, and i cannot connect with my code mentioned above – Fath Bakri Jan 13 '21 at 12:00

1 Answers1

0

I add SQL Browser Service UDP Port 1434 on firewall and worked fine. Use SQL Server Management Studio to connect remotely to an SQL Server Express instance hosted on an Azure Virtual Machine

Fath Bakri
  • 161
  • 1
  • 12