sql-server-ce

Is using a (sequential) GUID the only viable alternative to a database generated ID?

与世无争的帅哥 提交于 2019-12-13 16:09:41
问题 We are migrating our MS-Access database to SQL Server Compact 4.0 using the Entity Framework 5 Code First approach. We found that using Database generated Integer ID's is very slow and to make it worse, the delay increases exponentially with the size of the database. This makes using an Identity column impossible and it seems there is a bad implementation of this feature in SQL Server Compact 4.0 paired with the Entity Framework. So, we ran some tests and found that using a client side

Entity Framework on SQL Server CE without driver install

家住魔仙堡 提交于 2019-12-13 16:05:26
问题 I'm developing a WPF application using Entity Framework 4 and SQL Server CE database 3.5 and it's correctly working. However I'd like to have this application to run on a machine with .Net Framework 4 installed but without the SQL Server Compact 3.5 drivers. And no installer. Is it possible? I have tried the following: create a section in the app.config <configuration> <connectionStrings> <add name="DbEntities" connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res

How connect to SQL Server Compact 4.0 in ASP.NET?

大憨熊 提交于 2019-12-13 12:55:33
问题 I want connect to SQL Server Compact 4.0 in my ASP.NET application. Here is example of code: protected void Page_Load(object sender, EventArgs e) { string connStr = "Data Source=D:\\MyDB.sdf;"; string sqlStr = "select * from tblMyTable"; var sqlDataSrc = new SqlDataSource(connStr, sqlStr); GridWithUrls.DataSource = sqlDataSrc; GridWithUrls.DataBind(); } But I have the next error: "A network-related or instance-specific error occurred while establishing a connection to SQL Server.The server

Unable to load the native components of SQL Server Compact

微笑、不失礼 提交于 2019-12-13 11:55:10
问题 I've installed SQL Server Compact Edition 4.0 on Win7 x64 and it runs both for Asp.Net and Desktop Applications. This PC also have Visual Studio 2010 SP1 installed. But my Server 2008 R2 produces following error for Asp.Net applications, although it can run Desktop Applications: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8482. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details. I've

Insert to a SQL Server CE database

倖福魔咒の 提交于 2019-12-13 09:17:49
问题 How do you insert into a table in a .sdf database? I've tried the following: string connection = @"Data Source=|DataDirectory|\InvoiceDatabase.sdf"; SqlCeConnection cn = new SqlCeConnection(connection); try { cn.Open(); } catch (SqlCeException ex) { MessageBox.Show("Connection failed"); MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.ExitThread(); } string clientName = txt_ClientName.Text; string address = txt_ClientAddress.Text;

What is the fastest way to find data in SQLCE in Windows Mobile (using C#)?

China☆狼群 提交于 2019-12-13 08:59:52
问题 What is the fastest way to find data in SQLCE in Windows Mobile (using C#)? I have a database with one million records. Is the fastest way an SQL query, a DataReader, or what? 回答1: Use an index for your where clause and a SqlConnection. 回答2: By far the fastest way is to not use the query processor at all. Index the table to the field you want to search on and then use a SqlCeCommand with TableDirect and open a reader. Just adding the query procesor makes it an order of magnitude slower. 回答3:

SQL CE Not entering information to DB

佐手、 提交于 2019-12-13 08:06:58
问题 When i run my application, it goes through to the end just fine, but when i check my DB afterwards, it never shows any data. Here is my code: private void button1_Click(object sender, EventArgs e) { string saltedcryps = saltpassword(10); string passWithSalt = (textBox1.Text + saltedcryps); string hashedResult = hashPassAndSalt(passWithSalt); if (checkPasswordsMatch() == "B") { SqlCeConnection myConnection = new SqlCeConnection("Data Source = pwdb.sdf"); try { myConnection.Open(); } catch

What is the most efficient way to check an ExecuteScalar result for existence?

≯℡__Kan透↙ 提交于 2019-12-13 08:04:28
问题 I'm seeing this code: object objvalid = cmd.ExecuteScalar(); //made it this far - must not have thrown an exception retVal = true; ...but am thinking one of these might be better: object objvalid = cmd.ExecuteScalar(); retVal = (null != objvalid); ... Int32 anybodyThere = (Int32) cmd.ExecuteScalar(); retVal = anybodyThere > 0; 回答1: I think you answered your own question. You can't get much better than this object objvalid = cmd.ExecuteScalar(); retVal = (null != objvalid); However, from your

Insert problems to .sdf database C#

风流意气都作罢 提交于 2019-12-13 07:54:02
问题 When i run the program it doesn't seem to have any errors but it doesn't insert any data to the database. Is there some essential code missing? Here's my code: Using string connection = @"Data Source=|DataDirectory|\InvoiceDatabase.sdf"; SqlCeConnection cn = new SqlCeConnection(connection); try { cn.Open(); } catch (SqlCeException ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.ExitThread(); } SqlCeCommand cmd = new

T-SQL, SQL Server Compact Edition, Alias For SELECT

泪湿孤枕 提交于 2019-12-13 06:45:30
问题 How can I optimize my SQL code ? I want to add alias. I am using SQL Server Compact Edition. ( ... ) is a SELECT query SELECT * FROM ( ... ) WHERE id IN ( SELECT id FROM ( ... ) GROUP BY id HAVING COUNT( * ) > 1 ) 回答1: I would suggest to use that query only once. You can create a CTE of that query and then write the query as follows: with cte As (....) Select * from cte where id in (select id from cte group by id having count(*) > 1) Hope it helps 回答2: this is another option: SELECT * FROM