ado.net

Creating a new database (.mdb) with ADO.NET

How can I create a empty .mdb file? I'm using ADO.NET and C#. Thanks! ...

ADO.NET Data Services 'Astoria' and Caching

Hello all, I just started diving into ADO.NET Data Services for a project, and I quickly ran into a problem. At first I was amazed by the performance, but then I realized that the data was cached. My project relies on real-time data, and I'd love to use the ADO.NET Data Services REST query syntax (without needing to use WCF or SOAP), bu...

How to specify format of XML output when writing from a DataTable?

In C#, I'm creating an XML file from a DataTable using dataTable.WriteXml(filePath), and get the following: <?xml version="1.0" encoding="utf-8" ?> <ExperienceProfiles> <ExperienceProfile> <Col1>blah</Col1> <Col2>4ed397bf-a4d5-4ace-9d44-8c1a5cdb0f34</Col2> </ExperienceProfile> </ExperienceProfiles> How can I get it to writ...

ADO.NET Entity : getting data from 3 tables

I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party PartyID: Primary Key PartyName: String PlantID: link to Plant table Table: Customer PartyID: Primary Key, link to Party CustomerCode: String I'd like to have Customer entity object with following fields: PartyID: Primary Key ...

DataReader with duplicate column names

What is the best way of handling trying to get data from a DataReader that has more than one column with the same name? Because of the amount of work involved and because we don't want to lose support from a vendor by changing the stored procedures we are using to retrieve the data, I am trying to find another way to get access to a col...

how sqlConnection hides the password of the connection string

Hi all, I'm making a component which uses some data to connect to a database, this data includes user id and password, it store those values in private variables but any programmer can see the value in the debugger after the initialization, so I'm wondering how the SqlConnection does to hide that value, when I see the value of the prope...

ADO.NET Data Services

I'm looking at using ADO.NET Data Services with silverlight. I've been looking at the Data Model and Data Service Implementations (ADO.NET Data Services/Silverlight) topic on msdn. In their example, they build a data model generated from a database, and query entities in the datamodel. In my case I want to use stored procedures, so I...

How to map a related table to an inherited entity (table-per-hierarchy)?

Hi erverybody, i've got this tables in my database. With Entity Framework i would like to have something like that: I've used table-per-hierarchy inheritance, so i added a new entity for the premium user and map it to the user entity with conditions to IsPremiumUser property. I would like to have the PremiumAccount table associate...

Datareader returns no results in VS yet Stored Procedure returns multiple result sets in Sql Server

I am having trouble retrieving results from my datareader in visual studio 2008. I have several stored Procs in the same database. I am able to retrieve values from those that dont receive input parameters. However, when i use the executreReader() method on a stored proc with input parameters i get an empty datareader. Upon examining the...

How can I find the primary key columns of a table using ado.net?

Is there a pure .net way to do this reliably? The solutions I keep finding either require guessing or they have a solution that is specific to a database provider. Usually querying some internal system table to get this information. ...

SqlBulkInsert - How to set Fire Triggers, Check Constraints?

I'm performing a bulk insert with an ADO.NET 2.0 SqlBulkCopy object from a C# method into a MS SQL 2005 database, using a database user with limited permissions. When I try to run the operation, I get the error message: Bulk copy failed. User does not have ALTER TABLE permission on table 'theTable'. ALTER TABLE permission is r...

Does an ADO.NET DataReader read a whole row, or does it only read the columns you "Get"?

If I do something like this: using (SqlCommand cmd = new SqlCommand("SELECT * FROM TBL")) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string s = reader.GetString(7); } } } does the Read() call read the entire row into memory, or does the GetString(7) ca...

Why is a DataViewManager not sorting?

First off, a quick rundown of what the code is doing. I have two tables: Companies and Clients. There is a one to many relationship between Companies and Clients (one company can have many clients). In some processing logic, I have both tables loaded into a DataSet - each are DataTables. I have added a DataRelation to set the relationsh...

NHibernate not persisting collections

Hi, I have a rather strange error with NHibernate. I am was having error with ISession been shared by across threads and got this resolved by supplying my own ADO.NET connection like: IDbConnection connection = new SqlConnection(ApplicationConfiguration.ConnectionString); connection.Open(); ISession...

How to safely and effectively cache ADO.NET commands?

I want to use this pattern: SqlCommand com = new SqlCommand(sql, con); com.CommandType = CommandType.StoredProcedure;//um com.CommandTimeout = 120; //com.Connection = con; //EDIT: per suggestions below SqlParameter par; par = new SqlParameter("@id", SqlDbType.Int); par.Direction = ParameterDirection.Input; com.Parameters.Add(par); H...

Correct way to escape characters in a DataTable Filter Expression

Hi I would like to know if there is a function to correctly escape string literals for filter expressions. e.g. DataTable.Select(String.Format("[name] = '{0}'", MyName)) If MyName contains ' or a number of other key characters an exception is generated. The Microsoft documentation indicates that these charaters should be correctly e...

Update more than one database using same ObjectDataSource using C#

Is there a way to update more than one Database having same schema using single ObjectDataSource in C#??? i.e Just by providing more than one connection string is it some how possible to update more than one Database? I need to update/insert same record in multiple Database with same schema using ObjectDataSource in C#. ...

C# Windows Application - Many threads using the same connection?

I've got a c# WINDOWS Application that is multi-threaded. It is my understanding that in a web environment, connections are pooled automatically. It is also my understanding that in a Windows app, this is not the case. Therefore, for a Windows app, the same connection should be used and not closed after each call, but instead closed when...

Multiple Connections With Same Connection String Under A Single Transaction, Elevated Transaction?

When using ado.net, and creating multiple connections to a MS SQL Server database within a single transaction (using System.Transactions.TransactionScope), does System.Transactions elevate the transaction from the lightweight transaction manager to the distributed transaction coordinator (kernel transaction coordinator on Vista), even if...

Strategies to Avoid Transaction Escalation in System.Transactions

So, based on the answer to my previous question, transactions do get elevated from the LTM to the DTC if multiple connections are opened during a transaction, even if the connections all have the same connection string. So, my next question is, what strategies could one employ to avoid this "feature?" It seems to me that, based on resou...