ado.net

Will SCOPE_IDENTITY Work in this Case?

半城伤御伤魂 提交于 2019-12-21 05:32:08
问题 I have PK that is self incrementing key. I need to insert the record into the database and then get that PK back and use it in another insert. However I would like to do this in one transaction. Is that possible. The idea is that if something fails in any of the updates/inserts I have to do then I can rollback everything but I am under the impression that I need to do a commit. I was going to do it in ado.net at first but then switched to a stored procedure since I thought maybe that would

ADO.NET SQLServer: How to prevent closed connection from holding S-DB lock?

谁都会走 提交于 2019-12-21 04:15:26
问题 i Dispose an SqlConnection object, but of of course it isn't really closed. i need closed connection to not hold locks on database objects. How can i prevent closed connections from holding locks? Explanation of the above sentance for those who don't know: When you close an ADO or ADO.NET connection, you aren't actually severing the connection to SQL Server. The ADO/ADO.NET infrastructure keeps the connection around in case you want to use it again. The connections are kept lingering around

ADO.NET data table vs. data reader

白昼怎懂夜的黑 提交于 2019-12-21 03:58:16
问题 The DataReader is more efficient than a DataTable if you only need to show data but not manipulate it. However, to get a DataReader from the data access layer should I leave the connection object open? I think this is also a very big efficiency problem. So is there another approach to this in order to take full advantage of the DataReader? 回答1: Yes, the data reader is definitely the most efficient - but you do not want to keep a connection open for a long period of time! use the DataReader to

.NET - How do I retrieve specific items out of a Dataset?

笑着哭i 提交于 2019-12-21 03:53:07
问题 I have the following code which connects to a database and stores the data into a dataset. What I need to do now is get a single value from the data set (well actually its two the first row column 4 and 5) OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString; DataSet ds = new DataSet(); OdbcDataAdapter da = new OdbcDataAdapter("SELECT * FROM MTD_FIGURE_VIEW1", conn); da.Fill(ds) So, I need to get two

How can I return a datareader when using Entity Framework 4?

白昼怎懂夜的黑 提交于 2019-12-21 03:31:06
问题 I want to define a database query using LINQ and my EntityFramework context but I don't want entities returned; I want a datareader! How can I do this? This is for exporting rows to a CSV. Cheers, Ian. 回答1: This question is around EF 4, but for anyone else with EF 6 or higher you can use the AsStreaming() extension method. http://msdn.microsoft.com/en-us/library/dn237204(v=vs.113).aspx 回答2: If you need this you are more probably doing something unexpected. Simple iteration through

Fastest way to map result of SqlDataReader to object

故事扮演 提交于 2019-12-21 02:28:16
问题 I'm comparing materialize time between Dapper and ADO.NET and Dapper. Ultimately, Dapper tend to faster than ADO.NET, though the first time a given fetch query was executed is slower than ADO.NET. a few result show that Dapper a little bit faster than ADO.NET(almost all of result show that it comparable though) So I think I'm using inefficient approach to map result of SqlDataReader to object. This is my code var sql = "SELECT * FROM Sales.SalesOrderHeader WHERE SalesOrderID = @Id"; var conn

Enable ODP.Net logging

心已入冬 提交于 2019-12-21 01:21:25
问题 Can anyone help me with enabling ODP.Net logging on a Windows XP machine? I googled and found following link but it did not work for me. http://download.oracle.com/docs/html/E10927_01/featConfig.htm I set the "TraceLevel" setting to "63" in registry but it did not help Basically I want to capture all the database call happening from my C# code through the log. I wish there was a tool like "SQL Profiler" for Oracle. 回答1: I had the same issues on certain machines when troubleshooting some

Enable ODP.Net logging

╄→гoц情女王★ 提交于 2019-12-21 01:21:06
问题 Can anyone help me with enabling ODP.Net logging on a Windows XP machine? I googled and found following link but it did not work for me. http://download.oracle.com/docs/html/E10927_01/featConfig.htm I set the "TraceLevel" setting to "63" in registry but it did not help Basically I want to capture all the database call happening from my C# code through the log. I wish there was a tool like "SQL Profiler" for Oracle. 回答1: I had the same issues on certain machines when troubleshooting some

how to resolve DTS_E_OLEDBERROR. in ssis

耗尽温柔 提交于 2019-12-20 19:38:11
问题 In an ssis package consists of data flow task,contains OLEDB source and OLDB Target ..provider is sql native client..This used to run fine ..but now got an error as shown below.. Please tell me how to resolve it ?changing it to ado.net? OS :windows 7 professional and the db is sql server 2000 [Axe_Data [737]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult:

IEnumerable to string

杀马特。学长 韩版系。学妹 提交于 2019-12-20 17:34:45
问题 I have a DataTable that returns IDs ,1 ,2 ,3 ,4 ,5 ,100 ,101 I want to convert this to single string value, i.e: ,1,2,3,4,5,100,101 How can i rewrite the following to get a single string var _values = _tbl.AsEnumerable().Select(x => x); 回答1: var singleString = string.Join(",", _values.ToArray() ); 回答2: Write an extension method such as public static String AppendAll(this IEnumerable<String> collection, String seperator) { using (var enumerator = collection.GetEnumerator()) { if (!enumerator