- Home /
cannot connect database sdf compact version of MSSQL
I created a local database database.sdf and places it at the assets folder and tried to connect to it connectin string: string connectionString ="Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\Database1.sdf;Persist Security Info=False";
trying to open and use it SqlConnection conn = new SqlConnection(connectionString); string sqlIns = "INSERT INTO Shelf (row,colume,depth,shelfType,isEmpty) VALUES (@row, @colume, @depth, @shelfType, @isEmpty)"; conn.Open(); try { SqlCommand cmdIns = new SqlCommand(sqlIns); cmdIns.Parameters.AddWithValue("@row", shelf.row); cmdIns.Parameters.AddWithValue("@colume", shelf.colume); cmdIns.Parameters.AddWithValue("@depth", shelf.depth); cmdIns.Parameters.AddWithValue("@shelfType", shelf.shelfType); cmdIns.Parameters.AddWithValue("@isEmpty", shelf.empty); cmdIns.ExecuteNonQuery(); cmdIns.Dispose(); cmdIns = null; } catch (Exception SockEx) { Debug.Log("Socket exception: " + SockEx.Message); }
finally
{
conn.Close();
}
I get SocketException:
SocketException: לא מוכר מחשב מערך כזה.
System.Net.Dns.GetHostByName (System.String hostName) System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) System.Net.Sockets.UdpClient.Connect (System.String hostname, Int32 port) System.Net.Sockets.UdpClient..ctor (System.String hostname, Int32 port) System.Data.SqlClient.SqlConnection+SqlMonitorSocket..ctor (System.String ServerName, System.String InstanceName) System.Data.SqlClient.SqlConnection.DiscoverTcpPortViaSqlMonitor (System.String ServerName, System.String InstanceName) System.Data.SqlClient.SqlConnection.ParseDataSource (System.String theDataSource, System.Int32& thePort, System.String& theServerName) System.Data.SqlClient.SqlConnection.Open () (wrapper remoting-invoke-with-check) System.Data.SqlClient.SqlConnection:Open () consol_manager.isShelf_empty (Int32 row, Int32 colume, Int32 depth) (at Assets/Scripts/consol_manager.cs:177) setEmptyTrays.Awake () (at Assets/Scripts/setEmptyTrays.cs:23)
unrecognized host tried spacifing direct address and it want work I googled and found that to use the sdf file I should use SqlCeConnection but its not on system.data any help?
Answer by Tal770 · Jan 09, 2012 at 05:45 PM
To be more readable
created database.sdf file and placed it at the assest folder/
on db.open() i receive a socketException
I think becuse its a compact version of mssql and I should use SqlCeConnection but thats not included in the system.data
any help plase
Answer by Tal770 · Jan 09, 2012 at 06:03 PM
a direct pointing to the database1.sdf file
Data Source=C:/Users/MMS/Documents/AVM Project/Assets/Database1.sdf;Persist Security Info=Fals
the db.open() and the exception "unkown host" message
SocketException: לא מוכר מחשב מערך כזה.
System.Net.Dns.GetHostByName (System.String hostName) System.Net.Dns........... etc
the connect string is pointing at the database file and still it wont work
googling it says that I should use SqlCeConnect insted of SqlConnect for compact database
any body tried this?
Your answer
