0
votes

I had a problem loading the WebService to the IIS in my Cloud server this WebService to check username and password in sql server DB and return True or False in XML.

The WebService code :

public Result Login(string userName, string userPass)
    {
        SqlConnection conn = new SqlConnection(new DBConnection().ConnectionString);

        Result result = new Result();

        try
        {
            SqlCommand cmd = new SqlCommand("select username,password from users where username = @username and password = @password");
            cmd.Parameters.AddWithValue("username", userName);
            cmd.Parameters.AddWithValue("password", userPass);
            cmd.Connection = conn;

            if (conn.State == System.Data.ConnectionState.Closed)
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                result.ValidUser = true;
                return result;
            }
            else
                result.ValidUser = false;


        }

        catch (Exception ex)
        {
            result.Error = ex.ToString();
        }

        finally
        {
            conn.Close();

        }

        return result;
    }
-----------------------------------------------------------

Connection string :

public string ConnectionString
    {
        get
        {
            return "Data Source=localhost;Integrated Security=True;Initial Catalog=test";

        }
    }

and i swap the localhost with my public IP of my server but not work

this is the message error appear when executed

Error :

<Error>

System.Data.SqlClient.SqlException (0x80131904): 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at WebApplication.WebService.Login(String userName, String userPass) ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:2,State:0,Class:20


Please help me

1

1 Answers

0
votes

Not to state the obvious, but if you get the above message, which says

"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"

the first things you might wanna check are:

  1. The server address
  2. The database instance name
  3. The configuration of your SQL Server

For the first 2 points, you might wanna try this connection string type out

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

For the last point, follow this link.

Remote connection configuration