ado.net

Supplying stream as a source of data for a binary column when SqlBulkCopy is used

末鹿安然 提交于 2020-01-23 13:29:07
问题 If one needs to read data from SqlServer in a streamed fashion, there are some capabilities for that. Such as using SqlDataReader with CommandBehavior.SequentialAccess , and particularly when binary column data needs to be accessed there is the GetStream(int) method for that: var cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandText = @"select 0x0123456789 as Data"; using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); var stream = dr.GetStream(0); /

Supplying stream as a source of data for a binary column when SqlBulkCopy is used

大兔子大兔子 提交于 2020-01-23 13:28:09
问题 If one needs to read data from SqlServer in a streamed fashion, there are some capabilities for that. Such as using SqlDataReader with CommandBehavior.SequentialAccess , and particularly when binary column data needs to be accessed there is the GetStream(int) method for that: var cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandText = @"select 0x0123456789 as Data"; using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); var stream = dr.GetStream(0); /

SQLTransaction has completed error

天大地大妈咪最大 提交于 2020-01-23 04:50:36
问题 I got following error once in my application. This SQLTransaction has completed; it is no longer usable Stack Trace is attached below – It says about Zombie Check and Rollback . What is the mistake in the code? Note: This error came only once. UPDATE From MSDN - SqlTransaction.Rollback Method A Rollback generates an InvalidOperationException if the connection is terminated or if the transaction has already been rolled back on the server. From Zombie check on Transaction - Error One of the

Entity Framework 4 with Existing Domain Model

天大地大妈咪最大 提交于 2020-01-22 12:56:40
问题 Im currently looking at migrating from fluent nHibernate to ADO.Net Entity Framework 4. I have a project containing the domain model (pocos) which I was using for nHibernate mappings. Ive read in blogs that it is possible to use my existing domain model with EF4 but ive seen no examples of it. Ive seen examples of T4 code generation with EF4 but havent come accross an example which shows how to use existing domain model objects with EF4. Im a newby with EF4 and would like to see some samples

Defining an Entity Framework 1:1 association

旧街凉风 提交于 2020-01-22 09:25:10
问题 I'm trying to define a 1:1 association between two entities (one maps to a table and the other to a view - using DefinedQuery) in an Entity Framework model. When trying to define the mapping for this in the designer, it makes me choose the (1) table or view to map the association to. What am I supposed to choose? I can choose either of the two tables but then I am forced to choose a column from that table (or view) for each end of the relationship. I would expect to be able to choose a column

I keep getting this error: “Invalid attempt to call Read when reader is closed”

落花浮王杯 提交于 2020-01-22 03:26:06
问题 Here is my code, I close and open the reader and it's still not working. A few threads can access this function concurrently but there is a lock. It works a few times in the beginning but sooner or later I get the exception 'Invalid attempt to call Read when reader is closed' at private IList<BursaUser> GetUsers(SqlCommand cmd) { IList<User> users = new List<User>(); User user; lock (thisLock) { SqlDataReader dr = null; try { Conn.Open(); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection

Error Using ADO.NET Entity Framework

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-21 11:45:14
问题 I want to convert a list to EntityCollection. List<T> x = methodcall(); EntityCOllection<T> y = new EntityCollection<T>(); foreach(T t in x) y.Add(t); I get this error. The object could not be added to the EntityCollection or EntityReference. An object that is attached to an ObjectContext cannot be added to an EntityCollection or EntityReference that is not associated with a source object. Anyone know about this error? 回答1: It sounds like x is the result of an ObjectContext query. Each

Insert method of TableAdapter not working?

末鹿安然 提交于 2020-01-20 08:06:19
问题 I'm using ADO.NET in my C# project. In my form I added a SourceBinding element from my toolbox in VS2010. I set the connection to the table of my dataset. It creates a DataAdapter automaticly for my. I want to insert a record, so I call the Insert() method of the DataAdapter. But when I view my database data, it doesn't have any new records... orderID = this.orderTableAdapter.Insert("", "", (int)OrderStatus.IN_CONSTRUCTION, DateTime.Now); Or do I need to insert it manually with the SqlCommand

How to update Dataset Parent & Child tables with Autogenerated Identity Key?

旧城冷巷雨未停 提交于 2020-01-19 12:56:44
问题 I am using ADO.NET Datasets in my VB Applications. I have a typed dataset with one Parent table and many child tables. I want to generate Identity Key when I insert data into Parent Table and then update the data in all child tables with the Same key (As Foregin key). At last, I want to update the dataset in Database(SQL Server08). Well, the above thing can be possible by first inserting Parent Table in Database directly, get the Identity column and than use to for Child tables. But I want to

How to give ADO.NET Parameters

。_饼干妹妹 提交于 2020-01-19 01:42:25
问题 I want to create a SQL command that adds record to DB. I tried the following code but it doesn't seem to be working: SqlCommand comand = new SqlCommand("INSERT INTO Product_table Values(@Product_Name,@Product_Price,@Product_Profit,@p)", connect); SqlParameter ppar = new SqlParameter(); ppar.ParameterName = "@Product_Name"; ppar.Value = textBox1.Text; MessageBox.Show("Done"); comaand.Parameters.Add(ppar); 回答1: In your case, it looks like you're using .NET. Using parameters is as easy as: C#