ado.net

why does my .NET 2.0 application crash under .NET 4.0 when I use a OleDbDataAdapter object without an OleDBConnection object?

六月ゝ 毕业季﹏ 提交于 2019-12-23 10:16:01
问题 This is a .NET 2.0 application written using VS 2005. It works fine on systems running .NET 2.0, but hard crashes on systems running .NET 4.0. Here's the critical section of the code: string selectCommand1 = .... string connectionString1 = .... using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand1, connectionString1)) { try { adapter.Fill(table1); } catch { MessageBox.Show("error"); } } string selectCommand2 = .... string connectionString2 = .... using (OleDbDataAdapter

ADO.Net (Azure AD) error “keyword not supported : authentication ”

和自甴很熟 提交于 2019-12-23 09:59:52
问题 I am trying to connect to Azure db with Azure AD credentials through c# code (Code is below). It works fine on my system. But when I deploy it to a 32 bit VM, it shows error "Keyword not supported : authentication". The VM has .Net framework 4.5 installed (But not Visual Studio). Application is targeting .Net Framework 4.5. As per my observations, system.data for framework 2.0 does not support authentication keyword for SQLConnection class. But my application is targetting 4.5 , so it should

Pass an array as value in an ado.net DBParameter

試著忘記壹切 提交于 2019-12-23 09:41:56
问题 The project I'm working on has a lot of IN-queries like: SELECT something, anotherthing FROM atable WHERE something IN (value1, value2, value3) This is an example of a query with 3 parameters in the IN-part but the same query could be executed with 1 or 2 or 5 or 10 or ... parameters. The problem is that each query has an other execution plan in the database with makes it slow. I'd like to hava a query like this: SELECT something, anotherthing FROM atable WHERE something IN (@value1, @value2,

How to split Oracle sql statements for ADO.NET

戏子无情 提交于 2019-12-23 09:38:08
问题 What is the proper way to split up SQL statements to send to an Oracle ADO.NET client? For instance, lets say you have the following code in a text file and want to execute these statements: CREATE TABLE foo (bar VARCHAR2(100)); INSERT INTO foo (bar) VALUES('one'); INSERT INTO foo (bar) VALUES('two'); I believe trying to send all those in one Command will cause Oracle to complain about the ";". My first thought would be to split on ";" character, and send them one at a time. But, Stored

one-to-one relationships in Entity Framework 4 v2 with POCO

╄→尐↘猪︶ㄣ 提交于 2019-12-23 09:26:31
问题 I've been looking for an example about how to build an one-to-one relationship in EF4v2 with POCO's. I found a lot of examples that show only how to create one-to-many or many-to-many. Do you have any resource about it? 回答1: This worked for me. using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using System.Linq; class Program { static void Main

Very slow foreach loop

☆樱花仙子☆ 提交于 2019-12-23 08:51:43
问题 I am working on an existing application. This application reads data from a huge file and then, after doing some calculations, it stores the data in another table. But the loop doing this (see below) is taking a really long time. Since the file sometimes contains 1,000s of records, the entire process takes days. Can I replace this foreach loop with something else? I tried using Parallel.ForEach and it did help. I am new to this, so will appreciate your help. foreach (record someredord

Prevent SQL injection in oracle

筅森魡賤 提交于 2019-12-23 06:09:18
问题 firstly i tried using following code strQuery = @"SELECT PASSWORD FROM IBK_USERS where upper(user_id) =upper('" + UserPrefix + "')"; try { ocommand = new OracleCommand(); if (db.GetConnection().State == ConnectionState.Open) { ocommand.CommandText = strQuery; ocommand.Connection = db.GetConnection(); odatareader = ocommand.ExecuteReader(); odatareader.Read(); and finally i converted above query to prevent sql injection like that strQuery = @"SELECT PASSWORD FROM IBK_USERS where upper(user_id)

How to get column names and other metadata from a table or resultset

邮差的信 提交于 2019-12-23 05:33:12
问题 EX In "Data" table type of column from moisture to end is Boolean I want to get column name has data is "1" to combobox Specifically, for each row of my result set, I need a collection of those column names which contain the value 1 so I can populate a combobox. Sorry for my English I'm not good enough. pic "Data" table 回答1: Using the MySQL .net connector (and any RDMS connector) when you are reading a result set from a query, you will have a DataReader object. In MySQL's case it is a

Checking if Table Exists Keeping Connection Open in SQLite

风流意气都作罢 提交于 2019-12-23 04:50:14
问题 So I have a method which is supposed to check if a table exists in a database which is defined as follows: internal override bool TableExists(string tableName) { bool tableExists = false; // Check the Tables schema and see if the table exists using (SQLiteConnection conn = (SQLiteConnection) CreateConnection()) { conn.Open(); DataRow[] rows = conn.GetSchema("Tables").Select(string.Format("Table_Name = '{0}'", tableName)); tableExists = (rows.Length > 0); } // Actually called elsewhere in the

How to use SQL Server table hints while using LINQ?

自作多情 提交于 2019-12-23 04:09:07
问题 What is the way to use Sql Server's table hints like "NOLOCK" while using LINQ? For example I can write "SELECT * from employee(NOLOCK)" in SQL. How can we write the same using LINQ? 回答1: Here's how you can apply NOLOCK: http://www.hanselman.com/blog/GettingLINQToSQLAndLINQToEntitiesToUseNOLOCK.aspx (Quote for posterity, all rights reserved by mr scott): ProductsNewViewData viewData = new ProductsNewViewData(); using (var t = new TransactionScope(TransactionScopeOption.Required, new