ado.net

how to close connection/datareader when using SqlDataSource or ObjectDataSource

☆樱花仙子☆ 提交于 2020-01-01 09:45:15
问题 during beta testing we discovered connection pooling error messages . Therefore I have been going through the code and closing down the SqlDataReader objects wherever they have been left unclosed. What I need to know is how to close a datareader (or if there is a need at all to close) that is specified in the SelectStatement attribute of the SqlDataSource or ObjectDataSource tags. Could there be connection leak if they are not handled? Thanks in advance ! 回答1: I tend to use the "using"

how to close connection/datareader when using SqlDataSource or ObjectDataSource

不打扰是莪最后的温柔 提交于 2020-01-01 09:45:08
问题 during beta testing we discovered connection pooling error messages . Therefore I have been going through the code and closing down the SqlDataReader objects wherever they have been left unclosed. What I need to know is how to close a datareader (or if there is a need at all to close) that is specified in the SelectStatement attribute of the SqlDataSource or ObjectDataSource tags. Could there be connection leak if they are not handled? Thanks in advance ! 回答1: I tend to use the "using"

Roll back in c#

亡梦爱人 提交于 2020-01-01 08:49:07
问题 I have 2 tables enquiry and details. On save button click I have written fbsave(); fbsavedetails(); fbsave() save the data in enquiry table and fbsavedetails() saves data in details table. now if error occur in fbsavedetails() then both steps should be rollback. is it possible? 回答1: You can explicitly create a transaction and pass that around, i.e. using(var connection = ...) { connection.Open(); using (var tran = connection.BeginTransaction()) { try { FBSave(connection, tran); FBSaveDetails

Is there any performance gain from CommandBehavior.SequentialAccess?

大憨熊 提交于 2020-01-01 08:41:52
问题 I realized I always read my fields in the order they are returned by index (using constants). So my code is already compatible with CommandBehavior.SequentialAccess as far as i understand. Would there be any benefits if i turn it on? DataReader is already forward only, read only which is the real performance gain right? 回答1: The main usage of this is when you are reading very large CLOB ( nvarchar(max) etc) or BLOB ( varbinary(max) ) fields. In the default usage, it buffers the entire row of

Is there any performance gain from CommandBehavior.SequentialAccess?

吃可爱长大的小学妹 提交于 2020-01-01 08:41:04
问题 I realized I always read my fields in the order they are returned by index (using constants). So my code is already compatible with CommandBehavior.SequentialAccess as far as i understand. Would there be any benefits if i turn it on? DataReader is already forward only, read only which is the real performance gain right? 回答1: The main usage of this is when you are reading very large CLOB ( nvarchar(max) etc) or BLOB ( varbinary(max) ) fields. In the default usage, it buffers the entire row of

Bulk insert questions

只谈情不闲聊 提交于 2020-01-01 07:09:20
问题 I have a CSV file at the client side, and I want to develop a C# application to bulk insert the data into a table of a database to minimal log output. I am confused about if I use ADO.NET at the client side to call stored procedures in the database server. What kind of code needs to develop at the client side and what kind of code needs to be implemented at the server side in the form of stored procedures? But I did not find any samples from Google. What are some ready to use samples? :-)

How to use C# to get column's description of Sql Server 2005?

对着背影说爱祢 提交于 2020-01-01 06:01:06
问题 I can use " Microsoft.SqlServer.Management.Smo.Table " in C# to get a table columns of a Sql Server 2005 database. I have got the column.Name, but how can I get the column's Description in C#? I have saw the link: SQL Server: Extract Table Meta-Data (description, fields and their data types) But how can I use C# "Microsoft.SqlServer.Management.Smo" dll to get a column's Description? 回答1: Say your Smo.Table object is named t. This will get the description: t.Columns["ProductID"]

Help with adding checkbox column to DataGridView in window form

北城余情 提交于 2020-01-01 05:27:26
问题 I am trying to add a checkbox column to a DataGridView in a simple window forms application. I am pulling back some data from a database using ADO.NET, putting into a datatable, and then setting the datagridview datasource to the datatable. I then want to add a checkbox column as the second column. So far I have this code that seems to work: ' Code here to connect to database Dim da As New SqlDataAdapter(cmd) Dim dt As New DataTable da.Fill(dt) MainForm.MyDataGridView.DataSource = dt Dim

using statement with connection.open

别等时光非礼了梦想. 提交于 2020-01-01 04:07:47
问题 I was looking at some code and discussing it with co-workers. Specifically a section of code that looks like this. [Test] public void TestNormalWay() { using(var cn = GetConnection()) { cn.Open(); // do stuff } } The question came up: "why not move the cn.Open into the GetConnection method." I said that if "Open" throws an exception dispose would not get called. His response was "So what. The connection wasn't opened so why would it need to get closed (or disposed)?" For me it is just a

Custom .NET Data Providers

大城市里の小女人 提交于 2020-01-01 02:49:08
问题 Is is possible to use a custom .NET data provider without installing it in the GAC? Can I reference a custom DLL and register it inside my configuration file? 回答1: Yes , you can register an implementation of the DbProviderFactory class by adding the following section in your configuration file: <system.data> <DbProviderFactories> <add name="My Custom Data Provider" invariant="MyCustomDataProvider" description="Data Provider for My Custom Store" type="MyNamespace.MyCustomProviderFactory,