admin管理员组

文章数量:1291147

Error Message:

[InsertUserData] SQL Error Details: Code: 0, Message: A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The operation completed successfully.

Problem:

I'm trying to connect my Unity project to a SQL Server 2005 instance on another PC. The SQL Server account (** with password ****) has full access and permissions (including db_owner and read/write). I can successfully ping the server’s IP address and port (e.g., 117.**.***.**, port 50001). Additionally, I can connect to the database from my laptop using SQL Server Management Studio. However, when I attempt to connect from Unity, I receive the error mentioned above during the login process.

  1. Set up the SQL Server:

    • Install and configure SQL Server 2005 on a remote PC.

    • Create a database (databasename) and user (<username> with password <password>).

  2. Setup in Unity:

    • Use the following connection string in my Unity project:

      string connectionString = "Data Source=<censored IP>;Initial Catalog=photolocation;User Id=<username>;Password=<password>;Encrypt=False;TrustServerCertificate=True;Persist Security Info=True;";
      
  3. Test Database Connection:

    • When attempting to connect to the database from Unity (using the InsertUserData method), I encounter the error above.

Expected Outcome:

  • Unity should successfully connect to the SQL Server and insert data into the database.

Actual Outcome:

  • The error message appears, and the connection does not complete.

Additional Information:

  • SQL Server 2005 is configured to accept SQL Server Authentication.

  • The account has the necessary permissions (db_owner, read/write).

  • I can ping the IP and connect via SQL Server Management Studio without issues.

  • The error only occurs within Unity and SQL server connection; it works fine in SSMS.

What I’ve Tried:

  • I've verified that SQL Server Authentication is enabled on the SQL Server instance.

  • I've ensured the correct IP and port are used in the connection string.

  • I've tested the connection via SQL Server Management Studio and it works fine.

  • I've made sure that firewall rules allow access on the necessary port.

本文标签: SQL Error Connection Establishedbut Login Fails in Unity with SQL Server 2005Stack Overflow