程式是這樣的,放在start里,連接本地資料庫DSOP,在management studio連接資料庫一切正常,Unity3D里一運行就報錯,試著把資料庫里的超時調成0了,但是沒有效果,應該怎么解決
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Data;
using System.Data.SqlClient;
public class SQLCOM : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
String s = @"Server=HUI-GOW\HUI;database=Master;uid=sa;pwd=123456;";
SqlConnection con = new SqlConnection(s);
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "select HP from ship" +
"where shipName = '夜鶯' ";
SqlDataAdapter sda = new SqlDataAdapter(com);
DataSet ds = new DataSet();
sda.Fill(ds, "ship");
print(ds);
ds.Dispose();
con.Close();
}
報錯資訊如下
SocketException: 遠程主機強迫關閉了一個現有的連接。
System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
System.Net.Sockets.Socket.EndReceiveFrom (System.IAsyncResult asyncResult, System.Net.EndPoint& endPoint) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
System.Net.Sockets.UdpClient.EndReceive (System.IAsyncResult asyncResult, System.Net.IPEndPoint& remoteEP) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
System.Net.Sockets.UdpClient.<ReceiveAsync>b__64_1 (System.IAsyncResult ar) (at <ae22a4e8f83c41d69684ae7f557133d9>:0)
System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as AggregateException: One or more errors occurred.
System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Data.SqlClient.SNI.SSRP.SendUDPRequest (System.String browserHostname, System.Int32 port, System.Byte[] requestPacket) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SNI.SSRP.GetPortByInstanceName (System.String browserHostName, System.String instanceName) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SNI.SNIProxy.CreateTcpHandle (System.Data.SqlClient.SNI.DataSource details, System.Int64 timerExpire, System.Object callbackObject, System.Boolean parallel) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SNI.SNIProxy.CreateConnectionHandle (System.Object callbackObject, System.String fullServerName, System.Boolean ignoreSniOpenTimeout, System.Int64 timerExpire, System.Byte[]& instanceName, System.Byte[]& spnBuffer, System.Boolean flushCache, System.Boolean async, System.Boolean parallel, System.Boolean isIntegratedSecurity) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SNI.TdsParserStateObjectManaged.CreatePhysicalSNIHandle (System.String serverName, System.Boolean ignoreSniOpenTimeout, System.Int64 timerExpire, System.Byte[]& instanceName, System.Byte[]& spnBuffer, System.Boolean flushCache, System.Boolean async, System.Boolean parallel, System.Boolean isIntegratedSecurity) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.TdsParser.Connect (System.Data.SqlClient.ServerInfo serverInfo, System.Data.SqlClient.SqlInternalConnectionTds connHandler, System.Boolean ignoreSniOpenTimeout, System.Int64 timerExpire, System.Boolean encrypt, System.Boolean trustServerCert, System.Boolean integratedSecurity, System.Boolean withFailover) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin (System.Data.SqlClient.ServerInfo serverInfo, System.Boolean ignoreSniOpenTimeout, System.Data.ProviderBase.TimeoutTimer timeout, System.Boolean withFailover) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (System.Data.SqlClient.ServerInfo serverInfo, System.Boolean redirectedUserInstance, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Data.ProviderBase.TimeoutTimer timeout) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (System.Data.ProviderBase.TimeoutTimer timeout, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Boolean redirectedUserInstance) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlInternalConnectionTds..ctor (System.Data.ProviderBase.DbConnectionPoolIdentity identity, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Object providerInfo, System.Boolean redirectedUserInstance, System.Data.SqlClient.SqlConnectionString userConnectionOptions, System.Data.SqlClient.SessionData reconnectSessionData, System.Boolean applyTransientFaultHandling) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlConnectionFactory.CreateConnection (System.Data.Common.DbConnectionOptions options, System.Data.Common.DbConnectionPoolKey poolKey, System.Object poolGroupProviderInfo, System.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningConnection, System.Data.Common.DbConnectionOptions userOptions) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection (System.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions options, System.Data.Common.DbConnectionPoolKey poolKey, System.Data.Common.DbConnectionOptions userOptions) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionPool.CreateObject (System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest (System.Data.Common.DbConnection owningObject, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionPool.TryGetConnection (System.Data.Common.DbConnection owningObject, System.UInt32 waitForMultipleObjectsTimeout, System.Boolean allowCreate, System.Boolean onlyOneCheckConnection, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal& connection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionPool.TryGetConnection (System.Data.Common.DbConnection owningObject, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal& connection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection (System.Data.Common.DbConnection owningConnection, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions, System.Data.ProviderBase.DbConnectionInternal oldConnection, System.Data.ProviderBase.DbConnectionInternal& connection) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal (System.Data.Common.DbConnection outerConnection, System.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection (System.Data.Common.DbConnection outerConnection, System.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, System.Data.Common.DbConnectionOptions userOptions) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlConnection.TryOpen (System.Threading.Tasks.TaskCompletionSource`1[TResult] retry) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.SqlClient.SqlConnection.Open () (at <290425a50ff84a639f8c060e2d4530f6>:0)
SQLCOM.Start () (at Assets/Resources/Scripts/SQLCOM.cs:15)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/32769.html
標籤:疑難問題
下一篇:資料庫收縮問題
