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 thor_tillas · Aug 17, 2011 at 04:32 PM · excelodbc

ODBCConnection.GetSchema make unity crash

Hi everyone,

For some days now, I try to connect an Excel file to a custom AssetImporter with an ODBCConnection. It's work pretty well. I am able to read it and parse the cells.

But I cannot get the list of the sheet name...

Along my research on this site or google, I found that "ODBCConnection.GetSchema("Tables")" will normally do the job... but as soon as I add this line to my code, Unity just crash... and I found no way to get the exception or any information back...

Has anybody already tryed this or get the same bug ? Any advices ?

Thanks in advance for all ! Thor

P.S. Hope my English is at least understandable... I really need some more practice... sorry... Don't hesitate to ask when any part is unclear ! P.P.S. Code source is not really relevant in this case but... sometimes it can help ^^

As Unity doesn't include the System.Data, I have create a new dll which I have put in my plugin folder. Here is the code of the unique class of the Dll.

 using System.Data;
 using System.Data.Odbc;
 using System.Data.OleDb;

 public class LocalisationExcelImporter : UnityEditor.AssetPostprocessor
 {
     private static string excelFileExtension = ".xls";
     private static string extendedExcelFileExtension = ".xlsx";

     public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
     {
         foreach (string assetPath in importedAssets)
         {
             if (assetPath.ToLower().EndsWith(LocalisationExcelImporter.excelFileExtension) ||
                 assetPath.ToLower().EndsWith(LocalisationExcelImporter.extendedExcelFileExtension))
             {
                 LocalisationExcelImporter.ReadXls(assetPath);
             }
         }
     }

     private static void ReadXls(string assetPath)
     {
         string applicationPath = System.IO.Path.GetDirectoryName(UnityEngine.Application.dataPath);
         string path = applicationPath + "/" + assetPath;

         try
         {
             string connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + path + ";";
             OdbcConnection odbcConnection = new OdbcConnection(connectionString);
             odbcConnection.Open();
                                        
             // ------> As soon as I add this line... it's crash... <------
             DataTable sheettable = odbcConnection.GetSchema("Tables");
             ////foreach(DataRow row in sheettable.Rows)
             ////{
             ////    UnityEngine.Debug.Log("sheet name : " + row["TABLE_NAME"].ToString());
             ////}
             string tableName = "Feuil1";

             string query = "SELECT * FROM [" + tableName + "$]";
             OdbcCommand odbcCommand = new OdbcCommand(query, odbcConnection);
             OdbcDataReader odbcReader = odbcCommand.ExecuteReader();
             
             DataTable datatable = new DataTable("copy");
             datatable.Load(odbcReader);
             
             odbcReader.Close();
             odbcConnection.Close();

             // DO SOMETHING with the file... Which works when I doesn't try to get the sheets names.
         }
         catch (System.Exception e)
         {
             UnityEngine.Debug.LogError("[LocalisationExcelImporter] : caught exception: " + e.ToString() + ", " + e.Message + "\n\n" + e.StackTrace);
         }
     }
 }
Comment
Add comment · Show 1
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 rlyle1179 · Oct 15, 2014 at 02:58 PM 0
Share

Hitting the same issue, would like to know as well..

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

can i retrieve excel datas in unity 5 Answers

"Load Data from Excel with Odbc" doesn't work in Unity 5 64bit 3 Answers

Retrieving metadata from an excel file 1 Answer

How can I get data from an outside database (specifically excel). 2 Answers

Can I use the Excel Object Library in a C# script in Unity? 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