ado.net

How to get efficient Sql Server deadlock handling in C# with ADO?

I have a class 'Database' that works as a wrapper for ADO.net. For instance, when I need to execute a procedure, I call Database.ExecuteProcedure(procedureName, parametersAndItsValues). We are experiencing serious problems with Deadlock situations in SQL Server 2000. A part of our team is working on the sql code and transactions to mini...

Is there a difference in the underlying protocol for ODBC, OLEDB & ADO.NET

When communicating to a SQL Server database using one of the typical systems, ODBC, OLEDB or ADO.NET, is the underlying basic protocol the same? Are all the differences between these systems basically just client side issues? Is this all just different flavors of TDS (Tabular Data Stream) transfer? [MS-TDS]: Tabular Data Stream Protoc...

Sorting the result of a stored procedure

I'd like to sort on a column in the result of a stored procedure without having to add the Order By clause in the stored procedure. I don't want the data to be sorted after I have executed the query, sorting should be part of the query if possible. I have the following code: public static DataTable RunReport(ReportQuery query)...

Is there a way to check the SQL generated by ADO.NET methods without resorting DB tracing/profiling?

I want to test that application A (legacy) and application B (current) are sending the same SQL to the database. Is there an easy way to check the generated SQL? I'm not too concerned with minor syntax differences. ...

How to fill DataTable from an in-memory Excel Worksheet

Our client gets Excel files in Excel's HTML format.(That's the way it arrives; nobody has any control over that.) We then need to run a report based on the data in the file. Using ADO.NET (OleDbReader) results in a "External file not in expected format" exception. If the data is converted to regular Excel format it gets read in OK. Howe...

Insert statement generated using SQLParameter and datetime.now()

Hi there I have a SQL Datetime field in sql 2000. I have a stored proc called addPresentation. From my .Net code I add a sqlparameter as:- new SqlParameter("Date", SqlDbType.DateTime).Value=DateTime.now When I call the stored proc from code and observe sql profiler it is attempting to perform the insert as :- exec addPresentation @Na...

Retrieving a byte array stored in a INT field in the database

Hi, how do I retrieve the byte array stored in an integer column in my database? Do I first case it as int, then as byte[] ? byte[] permissions = (byte) Convert.ToInt(dr["myField"]); ? ...

Do I need to specify a SQL data type when using a SqlCommand?

Is there any provable reason why I should always specify the SQL data type for SqlCommand paramenters? ...

How To: Use DataRelation to perform a join on two DataTables in a DataSet?

How do I perform a join between two DataTables in a Dataset? I created a DataRelation between two tables….then what? I'm looking at one explanation on how to do it (http://www.emmet-gray.com/Articles/DataTableJoins.htm) which involves copying rows from tables to a result table? Is there a better way to do this? ...

Detecting DataRow changes from within a partial class

Let's say I have an interface representing a domain object: public interface IFoo { Bar Bar { get; } } The Bar type is a family of objects, each of which has a slightly different schema. In the database, this is represented as XML (this is a mobile app, so it is simply nvarchar, not a true XML column). I have a generated DataSet ...

Detecting that a DB Connection is in error

As part of our unit tests, we restore a blank database when the tests start . The unit tests then perform their tests by calling web services (hosted in the Visual Studio ASP.NET host). This works fine for us the first time the unit tests are run, however if they are re-run without restarting the web services, an exception is raised as...

Avoid connection timeout when using multiple threads and connection pool

I'm splitting up a readonly database operation into multiple chunks, (Each of which reads a subset of a very large amount of data, analyzes it and writes the results to a disk file). Each chunk performs a Select (into a datatable) on a new .net thread (using a delegate and BeginInvoke) There are more subsets of the data than there are ...

ASP.NET/ADO.NET: Handling many database connections inside a .NET Object?

Hi! We have a .NET object that does a lot of reading/writing with the database. Throughout the life cycle of this object (or the asp page that uses it), it may hit the database with a query/update anywhere from 1 to 10 times. Instead of opening and closing a database connection every time the object needs to hit the database, it simpl...

.NET equivalent of modern Java web architecture

Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring MVC for the web tier, Spring for the "Service"/business-logic-layer and an ORM mapper such as Hibernate for persistence. What is the equivalent in .NET? I guess ASP.NET is used for the web tier and ADO.NET for persistence but what is the equivale...

ADO.NET check if Rollback is possible

I'm asking myself if it is possible to check if in ADO.NET the current transaction can be rolled back. The msdn suggests the following implementation: private static void ExecuteSqlTransaction(string connectionString) { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); ...

Hook object load event in Entity Framework?

Is there an EF equivalent to LINQ to SQL's OnCreated partial? Several of my objects have XML fields that I would like to parse whenever the object is loaded from the db - I'd like to put the XML data into more friendly strongly-typed collections. I've already marked the XML field as private and hooked the SavingChanges event to re-buil...

CheckBoxField in GridView won't bind to a string field in the database

How do I bind a CheckBoxField in my GridView to an underlying db field that is a string. The string is either "1" or "0" but all the same the GridView won't willingly bind to it. What do I do. What is the best way to have a checkbox in the GridView and have it get and set the string in the database (or the underlying datasource). ...

Connection Management ASP.net

How do you manage your database connections in your ASP.Net application? My understanding tells me the "best" way is to open a connection, make a query, close the connection - and do that multiple times because connection pooling makes the cost negligable. The problem comes when I have a DAL where each method looks after its own connec...

Managing database connectivity with ADO.NET

We have an application that is built upon ADO.NET. We follow some simple best practices that allow us to make use of the connection pool. For example, a block of code that is using a database might look something like this: using( DbConnection dbConnection = GetDatabaseConnection() ) { doWork(); } FWIW, there's nothing spec...

Why doesn't Entity Framework support ODBC?

Is there a specific reason that the EF requires new data providers and can't make use of ODBC? I figured it had to be some ORM specific problem, but NHibernate works fine via ODBC. I'm using NHibernate and can continue to use Nhibernate, but I worry that I can't assume Nhibernate knowledge for any future programmers here. ...