c# - Unity 5.3.5f and SQL Server 2008 R2 : 'an existing connection was forcibly closed by the remote host' -
i have not yet received feedback post in unity answer forums posting here broaden visibility.
it appears question has been asked few times within unity forums no answers have fixed issues. i'm running unity 5.3.5f, sql server 2008 r2 express (was running sql server 2016 read mono dll's compatible sql server 2008). have correct mono dll's in assets folder referenced , built in project. i'm running database locally. can fine using sql server management studio , visual studio 2015 connects fine well. i've dropped firewall. right i'm trying work within unity ide. have verified incoming connections allowed in sql server management studio , tcp/ip enabled in sql server configuration manager.
furthermore, examining unity manual no documentation exists database connections far i've seen.
my code:
public string retrievetestdata(string query) { string sqlconnectionstring = "server=zzzz\\sqlexpress2008;" + "database=mydb;" + "user id=sa;" + "password=mypass;"; debug.log(sqlconnectionstring); sqlconnection con = new sqlconnection(sqlconnectionstring); try { con.open(); // error thrown here sqlcommand cmd = new sqlcommand(query, con); var fubar = cmd.executescalar(); con.close(); return fubar.tostring(); } catch (exception ex) { debug.log(ex.stacktrace); throw; } public void testquery() { debug.log(retrievetestdata("select top 1 * dbo.weapon")); }
my error:
socketexception: existing connection forcibly closed remote host.
stack trace:
at system.net.sockets.socket.receivefrom_nochecks_exc (system.byte[] buf, int32 offset, int32 size, socketflags flags, system.net.endpoint& remote_end, boolean throwonerror, system.int32& error) [0x00000] in :0 @ system.net.sockets.socket.receivefrom_nochecks (system.byte[] buf, int32 offset, int32 size, socketflags flags, system.net.endpoint& remote_end) [0x00000] in :0 @ system.net.sockets.socket.receivefrom (system.byte[] buffer, system.net.endpoint& remoteep) [0x00000] in :0 @ system.net.sockets.udpclient.receive (system.net.ipendpoint& remoteep) [0x00000] in :0 @ system.data.sqlclient.sqlconnection+sqlmonitorsocket.discovertcpport (int32 timeoutseconds) [0x00000] in :0 @ system.data.sqlclient.sqlconnection.discovertcpportviasqlmonitor (system.string servername, system.string instancename) [0x00000] in :0 @ system.data.sqlclient.sqlconnection.parsedatasource (system.string thedatasource, system.int32& theport, system.string& theservername) [0x00000] in :0 @ system.data.sqlclient.sqlconnection.open () [0x00000] in :0 @ (wrapper remoting-invoke-with-check) system.data.sqlclient.sqlconnection:open () @ assets.scripts.data.dbbase.retrievetestdata (system.string query) [0x00013] in c:\development\unity\twistedshadowsgame\twistedshadows\assets\scripts\data\dbbase.cs:23 unityengine.debug:log(object) assets.scripts.data.dbbase:retrievetestdata(string) (at assets/scripts/data/dbbase.cs:35) assets.scripts.data.dbbase:testquery() (at assets/scripts/data/dbbase.cs:43) assets.scripts.data.dbbase:start() (at assets/scripts/data/dbbase.cs:48)
all appreciated single item holding progress. if i've not posted or need post elsewhere please let me know. rather not have right separate rest service this. i'm confident unity has capabilities , read looks has been done many others successfully.
thanks in advance! ryan
pretty "late game" on this, found answer time ago. proper design pattern writing service make database calls, , having unity make calls service. else trying pull data db populate object in unity, preferred pattern.
thanks :)
Comments
Post a Comment