Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by alisator · Sep 25, 2012 at 01:55 PM ·

Unity 3D connection to (MS)SQL server

I have a school project - connect to MSSQL database, get some data for particular device, then in unity draw a graph, which will be bounded with some 3D object (devices in building etc.), I have time until December. It can be a desktop application or web application, or both. But I don't know, if on some free web server I can use Unity3D and technologies which I am asking for.

I was looking through the Internet and I couldn't find (even in Unity3D documentation), how it exactly works, I mean: on which technology Unity runs, which technologies it uses, or can be use. I find some sharps on forums, but you know...

I hope, there is a possibility how to to use in some way .NET to connect to MSSQL server... But I am looking for other ways, how to connect to database. I found SmartFoxServer and it looks great but maybe it is unnecessary? Some poeple recommended to write own socket, but I have no skills for do that in such a short time (and if I consider, that I have no clue how Unity works).

I am starting with Unity, so maybe someone know a good book about my questions. I found only game development, but nothing about Unity itself.

Thx a lot guys.

(If something, my Skype: teddinka1)

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by alisator · Nov 20, 2012 at 09:07 AM

Sorry for format of code, but Editor in Chroms doesnt work very well... Though, this works (maybe for future references) ;)

     public void connect(){
         
     
         string connectionString =
             "Server=servername;" +
             "Database=dbname;" +
             "User ID=userid;" +
             "Password=pass;" +
             "Integrated Security=True";
         
         result = new List<float> ();
         resultCas = new List<DateTime> ();
 
         using(SqlConnection conn = new SqlConnection(connectionString))
         {
             SqlCommand c; SqlDataReader da; SqlParameter param1; SqlParameter param2; SqlParameter param3; SqlParameter param4;
              conn.Open();
             c = new SqlCommand();
             c.Connection = conn;
             c.CommandType = CommandType.StoredProcedure;
             c.CommandText = "commandtext";
             param1 = c.Parameters.Add("@identify",SqlDbType.Int);        
             param1.Value = 1;
             param2 = c.Parameters.Add("@startTime",SqlDbType.DateTime);
             param2.Value = "2010-11-10 07:45:00.000";
             param3 = c.Parameters.Add("@endTime",SqlDbType.DateTime);
             param3.Value = "2010-11-12 10:15:00.000";
             param4 = c.Parameters.Add("@args",SqlDbType.NVarChar);
             param4.Value = "I";
             da = c.ExecuteReader();
             while (da.Read())
             {
                 resultCas.Add(da.GetDateTime(0));
                 result.Add((float)da.GetDouble(1));
             }
         }
     }
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
1

Answer by Zerot · Sep 25, 2012 at 02:14 PM

Unity's webplayer is its own plugin, so the host you use doesn't matter much, because the browser would run it. similar to how flash it does.

Regarding connecting to an database, you don't want to connect directly to a db. The reason being, not every db connector uses managed code and the webplayer can only run managed code. A secondary reason is that you would have the db credentials in your application meaning that it would be very easy to hack unless you use the user system of the db, but most shared hosts are very limited in what they allow for user control. The normal way to solve this, is to build a webservice that will interact between the unity application and the database. This also allows you to do extra checks on the server side.

Unity provides a www class that you can use to access content on the web. With that you can access the webserver you are hosting your webservice on.

In short:

  • You need to have a host with a database(this can be any free/cheap host)

  • You need to write a website that returns data(this can be in any language that the host supports. Most likely PHP in this case)

  • You need to retrieve the data generated by the site using unity(unity has the WWW class for that)

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
1

Answer by Meltdown · Sep 25, 2012 at 02:16 PM

Unity uses the MONO.NET framework, which is very similar to the Microsoft.NET framework. All you need to do is google for how to connect to a SQL Server database with .NET and C# and the code will be the same in Unity.

Check out this page http://www.mono-project.com/SQLClient

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cloud recognition in Vuforia 0 Answers

About the object disappeared, and computing 0 Answers

Use WII Balance to control GUI 0 Answers

Terrain Procedural Texturing based on height? 4 Answers

How can I show loading process during load resources? 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