ado.net

No MSDTC - Still getting "communication with underlying transaction manager failed"

Hi In my project I am using Ado.Net's DbTransaction object to manage transaction... Then why I am getting MSDTC related error - "communication with underlying transaction manager failed". Here is my code. DbTransaction trans = Connection.BeginTransaction(); //Code if (successfull) { trans.Commit(); } else { trans.RollBack();...

SPID of a SqlConnection (SQL-Server) in ADO.NET

Can I get a SPID from a SqlConnection Object (SQL-Server Database) in ADO.NET? Is the SPID always the same for a connection object during its lifetime ? ...

Problem exporting a dataset to excel from a webmethod using asp.net

Hi, I am trying to export a dataset to excel from asp.net page method(webmethod) using the following code. [WebMethod] public static void ExporttoExcel() { DataSet ds; productfactory pf=new productfactory(); ds = pf.getproducts(); HttpResponse response = HttpContext.Current.Response; // f...

Get raw dump of SQL queries sent via ADO.NET?

Is it possible (in managed .NET) to get access to all the SQL queries sent via ADO.NET (in my own application?) Meaning some way to hook into the underlying ADO.NET (SQL connections/commands) infrastructure and see all the issues SQL queries from my application? (not other applications, just the ones sent from my own process) ...

Is my overview of .Net Data Providers and ADO.Net correct?

Recently I had to type up some documentation on .net data providers and ado.net. I am trying to get feedback on my findings. Please review and provide corrections or opinions. Summary This is a high level summary of the basic .Net API’s for interacting with a database. As a developer with mainly a Java and PHP background I was unclea...

can't generate SSDL from SQLC

I can't generate SSDL from SQLCe. --------------------------- Microsoft Visual Studio --------------------------- Could not find the appropriate DbProviderManifest to generate the SSDL. The supplied provider invariant name 'System.Data.SqlServerCe.3.5' is not valid. --------------------------- OK --------------------------- Is it...

How to update an object using Entity Framework

Hi, I am able to add data, but not sure how should I update the data. I am getting AddObject,DeleteObject methods not found any method to update. Thanks ...

problem in inserting data into table in 24-073110-XX format ????.....

I need help insering an id into the database in ASP.net mvc (C#). Here theid is the primary key and it should be in the format 24-073110-XX, where XX represents a numeric value which should be incremented by 1. How should I insert the id in this format? ...

Getting duplicates count for each distinct value from a datatable

Hello I've a datatable which has a single text column 'Title' which can have multiple values with duplicates. I can remove the duplicates using a dataview. DataView v = new DataView(tempTable); tempTable = v.ToTable(true, "Title"); But how can i get the number of duplicates for each distinct value without any looping? ...

Sharing connection and transaction in a Data Access Layer

Hello, I'm building a Data Access Layer for my asp.net application. I would like to be able to share connection between different classes in order to manage transaction, but I don't know how to do that. Example: I have 2 classes, Order and OrderDetail. I will call my DAL Order class for a SQL insert of a new order. Inside the Insert ...

Where can I add an event handler To the RowUpdated event for a table adapter

I have strongly typed dataset and Data Access Layer top of it. I am extending partial class of tableadpater. public partial class InvoiceTableAdapter { public void OnRowUpdated(object sender, OleDbRowUpdatedEventArgs e) { MessageBox.Show("I am here"); } } Question: Where can i add event handler for this? ...

WCF Data Service Query seems to be retrurning duplcate rows on repeated queries

Hello, I have a data class that return some objects from a wcf dataservice to a silverlight app: void ExecuteWipReportQuery(DataServiceQuery qry) { context = new StaffKpiServices.HwfStaffKpiEntities(theServiceRoot); qry.BeginExecute(new AsyncCallback(a => { try ...

Concise usage of DBNull? (Ternary?)

Hey all, It seems that there's some type confusion in the ternary operator. I know that this has been addressed in other SO threads, but it's always been with nullables. Also, for my case I'm really just looking for a better way. I'd like to be able to use proc.Parameters[PARAM_ID].Value = string.IsNullOrEmpty(dest.Id) ? DBNull....

How can I check if the connected SQL Server is on the local machine?

Is there any way of telling, using C#, if the Sql Server I'm connected to in Ado.Net is on the local machine rather than remote? I'm wanting to know whether I have access to the file system where SQL Server stores, for example it's backup files. That would let me determine whether I would be able to delete a backup file programatically...

Most straightforward way to add a row to an SQL Server table in ADO.NET without hardcoded SQL?

Hi, I am wondering what the best / most efficient / common way is to add a row to an SQL Server table using C# and ADO.NET. I know of course that I can just create an SQL statement for that, but first, the destination table schema might vary, so I want to keep this flexible, and second, there are so much columns that I do not want to co...

MS SQL Connection string for default instance like for named instance

In my .NET application I am connecting to Microsoft SQL Server 2005 or 2008 database. User selects instance which the application shows it and then application should do something with this instance. I take instance names from the registry, HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL. I do not know if user selects de...

is a static method using the same variables for different calls

I have this method: public static IEnumerable<T> ExecuteReaderSp<T>(string sp, string cs, object parameters) where T : new() { using (var conn = new SqlConnection(cs)) { using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd...

How to get to the primary key of a self tracking entity?

I am trying to create a generic method that will retrieve an item by its id: public T GetByID(int id) { return (T) context.GetObjectByKey( new System.Data.EntityKey(context.DefaultContainerName + "." + context.CreateObjectSet<T>().EntitySet.Name, "ProductID", id)); } Basically I am able to infer ...

Using C# to Select from SQL database Table

Hello All- I have a List of UserID's and a open connection to SQL Server. How can I loop through this List and Select matching UserID with First_Name and Last_Name columns? I assume the output can be in a datatable? many thanks ...

DataTable optimal saving to sql database

Hello, I have DataTable with same structure in SqlServer DB Table. To save data in a this DataTable to Sql DB I use code below: sqlCommand mcd; for(int i=0;i<dataTable.Rows.Count;i++) { mcd=new SqlCommand(); cmd.CommandText="Insert into MSSQLtable values("+dataTable.Rows[i][0]+dataTable.Rows[i][1]+")"; cmd.ExecuteNonQuery(); } How c...