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
0
Question by sriram90 · Nov 12, 2010 at 07:31 AM · errordatabaseargumentexception

problem in database connection

hi guys,

I'm trying to connect Sqlite database into "server : localhost" and i'm getting some strange errors..can any one explain what mistake i have done??

the error is: Code:

1.System.ArgumentException: Invalid ConnectionString format for parameter "Server : localhost" at Mono.Data.Sqlite.SqliteConnection.ParseConnectionString () [0x00000] in :0 at Mono.Data.Sqlite.SqliteConnection.Open () [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteConnection:Open () at commonDatabaseScript.openConnection () [0x00011] in E:\sriram\projects\databa\Assets \commonDatabaseScript.cs:40 UnityEngine.MonoBehaviour:print(Object) commonDatabaseScript:openConnection() (at Assets/commonDatabaseScript.cs:45) commonDatabaseScript:insertData(String) (at Assets/commonDatabaseScript.cs:52) commonDatabaseScript:OnGUI() (at Assets/commonDatabaseScript.cs:109)

2.InvalidOperationException: Database is not open Mono.Data.Sqlite.SqliteCommand.InitializeForReader () Mono.Data.Sqlite.SqliteCommand.ExecuteReader (CommandBehavior behavior) Mono.Data.Sqlite.SqliteCommand.ExecuteReader () (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteCommand:ExecuteReader () commonDatabaseScript.doQuery () (at Assets/commonDatabaseScript.cs:70) commonDatabaseScript.OnGUI () (at Assets/commonDatabaseScript.cs:110)

can any one say wat's going on pls???

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 sriram90 · Nov 12, 2010 at 07:33 AM 0
Share

and here is my code: public static void openConnection() { string connectionString = "Server : localhost ; Database =testdata.db "; try { dbConnection = new SqliteConnection (connectionString); dbConnection.Open(); } catch(Exception e) { string temp1 = e.ToString(); print(temp1); } Debug.Log("Database connected"); }

public static void insertData(string x) { openConnection(); SqliteCommand dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = "INSERT into nametable(name1) values ('"+x+"');"; dbCommand.Dispose(); dbCommand = null; dbConnection.Close(); dbConnection = null; }

2 Replies

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

Answer by StephanK · Nov 12, 2010 at 09:13 AM

Your connection string is using the wrong syntax. This is an example how it should look like:

string Server = "localhost"; string Username = "my_username"; string Password = "my_password"; string Database = "my_database";

string ConnectionString = "Data Source=" + Server + ";"; ConnectionString += "User ID=" + Username + ";"; ConnectionString += "Password=" + Password + ";"; ConnectionString += "Initial Catalog=" + Database;

Comment
Add comment · Show 6 · 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 sriram90 · Nov 12, 2010 at 10:24 AM 0
Share

have i want to initialize all those into start() function?

avatar image sriram90 · Nov 12, 2010 at 10:33 AM 0
Share

string ConnectionString = "Data Source=" + Server +";" "UserID=" + Username +";" "Password=" + Password +";" "Initial Catalog=" + Database ";";

is it correct???

avatar image sriram90 · Nov 12, 2010 at 10:34 AM 0
Share

its Showing error as error CS1525: Unexpected symbol `UserID='

avatar image sriram90 · Nov 12, 2010 at 10:52 AM 0
Share

hi spree thanks for your reply,

but still i'm getting the same error which i have mentioned above,now my code is'

public static void openConnection() { string connectionString = "Server=localhost;" + "Database=testdata;" + "User ID=name;" + "Password=password";

     try
     {
         dbConnection = new SqliteConnection (connectionString);
         {
         dbConnection.Open();
         dbCommand.ExecuteNonQuery();
         }
     }
     catch(Exception e)
     {
         string temp1 = e.ToString();
         print(temp1);
     }
     Debug.Log("Database connected");
 }
avatar image StephanK · Nov 12, 2010 at 06:17 PM 1
Share

which error? and reading code in the comments section is really hard. maybe just edit your original question.

Show more comments
avatar image
1
Best Answer

Answer by sriram90 · Nov 13, 2010 at 05:11 AM

ya i got the clear ans now.....these errors are came from "connectionString " syntax.The exact code for when you pass it from a function is,

public void OpenDB(string localhost, string db, string name,string password,string false)
{
   connectionString = "host= " +localhost + ";Database= " +db + ";User ID= " +name + ";Password= " +password +";Pooling= " +false+ ";"; 
}
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

No one has followed this question yet.

Related Questions

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced) 4 Answers

Database Error (Sqlite) in unity 4.0 1 Answer

Versy confusing argumentoutofrangeexception error 1 Answer

Firebase Connection error 0 Answers

SQL connection problem 0 Answers


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