简体   繁体   English

C#Web服务在Cloud Server中的IIS中不起作用

[英]C# WebService not work in IIS in Cloud server

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. 我在将WebService加载到我的云服务器中的IIS时遇到问题,该WebService会检查sql服务器DB中的用户名和密码,并在XML中返回True或False。

The WebService code : WebService代码:

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 我将本地主机与服务器的公共IP交换,但无法正常工作

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. System.Data.SqlClient.SqlException(0x80131904):建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (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, DbConnec (提供程序:命名管道提供程序,错误:40-无法打开与SQL Server的连接)---> System.ComponentModel.Win32Exception(0x80004005):系统找不到在System.Data.SqlClient.SqlInternalConnectionTds中指定的文件。 ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,SqlCredential凭据,对象providerInfo,字符串newPassword,SecureString newSecurePassword,布尔型redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,DbConnectionPool池,字符串accessToken,布尔型applyTransientFaultHandling)位于System.Factory。选项,DbConnectionPoolKey池键,对象poolGroupProviderInfo,DbConnectionPool池,System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池,DbConnection owneringObject,DbConnectionOptions选项,DbConnec中的DbConnection owningConnection,DbConnectionOptions userOptions) tionPoolKey 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, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbCon System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)上的tionPoolKey poolKey,DbConnectionOptions userOptions)在System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal上) .ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&connection)at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObjects,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1重试,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbCon nectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 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 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection externalConnection,DbConnectionFactory connectionFactory,TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1重试)的System.Data.SqlClient.SqlConnection WebApplication.WebService.Login上System.Data.SqlClient.SqlConnection.Open()的.TryOpen(TaskCompletionSource`1重试)(String userName,String userPass)ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:2,State :0,Class:20


Please help me 请帮我

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" “找不到服务器或无法访问服务器。请验证实例名称正确,并且将SQL Server配置为允许远程连接”

the first things you might wanna check are: 您可能要检查的第一件事是:

  1. The server address 服务器地址
  2. The database instance name 数据库实例名称
  3. The configuration of your SQL Server 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 远程连接配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM