ado.net

How do i stop the The database file is locked exception?

天大地大妈咪最大 提交于 2019-12-23 03:46:07
问题 I have a multithreaded app that uses sqlite. When two threads try to update the db at once i get the exception Additional information: The database file is locked I thought it would retry in a few milliseconds. My querys arent complex. The most complex one (which happens frequently) is update, select, run trivial code update/delete, commit. Why does it throw the exception? How can i make it retry a few times before throwing an exception? 回答1: SQLite isn't thread safe for access, which is why

Working with MySQL in C#

巧了我就是萌 提交于 2019-12-23 02:53:15
问题 Here's my code to print the data to the terminal: public static void WriteData() { string connString = "SERVER=localhost;" + "DATABASE=db;" + "UID=user;" + "PASSWORD=pass;"; MySqlConnection connection = new MySqlConnection(connString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader reader; command.CommandText = "SELECT * FROM table1"; connection.Open(); reader = command.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) Console.Write

What is the best way to maintain an entity's original properties when they are not included in MVC binding from edit page?

谁说我不能喝 提交于 2019-12-23 02:52:10
问题 I have an ASP.NET MVC view for editing a model object. The edit page includes most of the properties of my object but not all of them -- specifically it does not include CreatedOn and CreatedBy fields since those are set upon creation (in my service layer) and shouldn't change in the future. Unless I include these properties as hidden fields they will not be picked up during Binding and are unavailable when I save the modified object in my EF 4 DB Context. In actuality, upon save the original

When application close, will DB connection close instantly?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 02:09:23
问题 This is something I has been always wonder.... will it? Because whenever I write code to use DB connection, I always somehow have to ensure is closed before process to next piece. But when if the I have a ChildWindow that open a connection in its constructor and not close it until it hits the Save Button or Cancel Button. Then if the whole Application got closed, will the DB connection close instantly? Or it has to wait for the timeout and will close automatically? EDIT: So I am trying to

How to prevent ADO.NET from altering double values when it reads from Excel files

被刻印的时光 ゝ 提交于 2019-12-23 01:43:10
问题 I have the following rows in my Excel input file: Column1 Column2 0-5 3.040 6 2.957 7 2.876 and the following code which uses ADO.NET to read it: string fileName = "input.xls"; var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName); var dbConnection = new OleDbConnection(connectionString); dbConnection.Open(); try { var dbCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", dbConnection); var dbReader = dbCommand

how to save the DataSet after making changes to the database?

风格不统一 提交于 2019-12-23 01:35:10
问题 if I have a DataSet called myDs and I edit a field in it by direct access in a loop like the following: for (int i = 0; i < myDS.Tables[TableName].Rows.Count; i++) { //some function or web method to get the id value of the record being updated int n = getNewNumber(); //updating the dataset record according to some condition if (n == 0) { myDS.Tables[TableName].Rows[i]["id"] = n; myDS.Tables[TableName].Rows[i]["description"] = "some data"; } else { myDS.Tables[TableName].Rows[i]["id"] = n;

how to save the DataSet after making changes to the database?

送分小仙女□ 提交于 2019-12-23 01:34:29
问题 if I have a DataSet called myDs and I edit a field in it by direct access in a loop like the following: for (int i = 0; i < myDS.Tables[TableName].Rows.Count; i++) { //some function or web method to get the id value of the record being updated int n = getNewNumber(); //updating the dataset record according to some condition if (n == 0) { myDS.Tables[TableName].Rows[i]["id"] = n; myDS.Tables[TableName].Rows[i]["description"] = "some data"; } else { myDS.Tables[TableName].Rows[i]["id"] = n;

Get the value of print statement of sql server in vb.net by using oledb

和自甴很熟 提交于 2019-12-23 00:25:48
问题 I am trying to create an query analyzer and executor. I wonder that how to get the output message of an transact-sql statement like 'PRINT' declare @msg varchar(100) set @msg = select [column] from [table name] where [column] = [condition] if @msg = 'SOMEVALUE' begin print 'This is first statement' end else begin print 'This is second statement' end can you please help me to get the value of print statement of above code in vb.net Thanks in advance 回答1: From MSDN: You can retrieve warnings

Default combobox first item mixed with database results

[亡魂溺海] 提交于 2019-12-22 18:49:08
问题 public static void fill_combo(string table, ComboBox cmb, string columns) { ds = new DataSet(); try { conn.Open(); da = new SqlDataAdapter($"SELECT {columns} FROM [{table}]", conn); da.Fill(ds, table); cmb.DataSource = ds.Tables[table]; cmb.ValueMember = ds.Tables[table].Columns[0].ToString(); cmb.DisplayMember = ds.Tables[table].Columns[1].ToString(); cmb.SelectedItem = null; cmb.Text = "Select..."; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { if (conn != null)

How to handle an association table linking the same 2 tables

蹲街弑〆低调 提交于 2019-12-22 18:12:55
问题 I am using Entity Framework 4.3 code first using an already existing database. There is a Users table that has the following columns: - UserID (int) - FirstName (string) - Surname (string) I have an association table called Impersonations . The Impersonations table is an association table between a user table and the same user table. A user can have a list of users. Here is the Impersonations table structure: - ImpersonateID (int primary key) - UserID (int FK to Users table's UserID column) -