Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheDeak · Jul 20, 2016 at 09:01 PM · unity 5databasesql

unity 5.3.5f sql 2008 r2 an existing connection was forcibly closed by the remote host

It appears this question has been asked a few times but no answers which have fixed my issues. I'm running unity 5.3.5f, sql server 2008 express r2 (was running sql 2016 but read that the mono dll's are only compatible up to sql 2008). i have the correct mono dll's in my assets folder properly referenced and built in my project. I'm running the database locally. I can get into it fine using sql server management studio and visual studio 2015 connects to it fine as well. i've completely dropped the firewall. This will be a client/server setup with this db code executing server side. right now i'm just trying to get it to work within the unity ide. I have also verified incoming connections are allowed in sql server management studio and that tcp/ip is enabled in the sql configuration manager.

My code:

public string RetrieveTestData(string query) { string sqlConnectionString = "Server=zzzz\\SQLEXPRESS2008;" + "Database=mydb;" + "User ID=sa;" + "Password=;";

         Debug.Log(sqlConnectionString);

         SqlConnection con = new SqlConnection(sqlConnectionString);

         try
         {
             con.Open(); // error on connect

             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 * from dbo.Weapon"));
     }

My error: SocketException: An existing connection was forcibly closed by the 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 at System.Net.Sockets.Socket.ReceiveFrom_nochecks (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint& remote_end) [0x00000] in :0 at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x00000] in :0 at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00000] in :0 at System.Data.SqlClient.SqlConnection+SqlMonitorSocket.DiscoverTcpPort (Int32 timeoutSeconds) [0x00000] in :0 at System.Data.SqlClient.SqlConnection.DiscoverTcpPortViaSqlMonitor (System.String ServerName, System.String InstanceName) [0x00000] in :0 at System.Data.SqlClient.SqlConnection.ParseDataSource (System.String theDataSource, System.Int32& thePort, System.String& theServerName) [0x00000] in :0 at System.Data.SqlClient.SqlConnection.Open () [0x00000] in :0 at (wrapper remoting-invoke-with-check) System.Data.SqlClient.SqlConnection:Open () at 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 help is greatly appreciated as this is the single item holding up all my progress. If I've not posted something or I need to post elsewhere please let me know.

thanks in advance! ryan

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vitaly-Abilevich · Aug 16, 2017 at 01:40 PM

I am having the same problem here, I am working with MS SQL Server 13

 public static string conne = "Data Source=GUILTYSPARK343\\SQLEXPRESSVWD;Initial Catalog=VWDemo;uid=Rusoski;pwd=asd1234567";
     public static SqlConnection conn;
 
 public static void Connect()
     {
         conn = new SqlConnection(conne);
 
         try
         {
             using (IDbConnection dbcon = new SqlConnection(conne))
             {
                 dbcon.Open();
             }
                 Debug.Log(conn.ConnectionString);
             conn.Close();
             conn.Open();
             
             Debug.Log("I was here0");
         }
         catch (Exception e)
         {
           Debug.Log(e);
         }
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by swapsshah · Feb 03, 2020 at 07:31 PM

Dear @TheDeak / @vitaly-Abileveh,

Were you able to get through this Exception? I have been struggling to get though this issue from past couple of days.

I have checked, re-checked and tried all SQL server side configurations. Also, we use MS SQL server on day to day basis. So I am pretty sure I am missing something on Unity Environment settings.

Kindly reply if something has worked for you.

Thanks in Advance.

Regards, Swapneel Shah

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to create table in GUI unity? 2 Answers

VR Highscore with database (SQLite) 1 Answer

Can't connect from Unity 3.1 to SQL Server Express 8 Answers

Best way to connect to database for my mobile game? 3 Answers

[Quiz game] How do I make players contribute with questions? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges