ado.net

Connection Management ASP.net

旧时模样 提交于 2020-01-13 17:07:15
问题 How do you manage your database connections in your ASP.Net application? My understanding tells me the "best" way is to open a connection, make a query, close the connection - and do that multiple times because connection pooling makes the cost negligable. The problem comes when I have a DAL where each method looks after its own connection. E.G. User x = DAL.GetUserDetails(); Customer y = DAL.GetCustomer(); This is fine until we start talking about TransactionScope using (TransactionScope t..

Ado.Net Entity : Object doesn't display linked members (foreign keys)

谁说胖子不能爱 提交于 2020-01-13 15:53:32
问题 I have a simple databasescheme: User, Account. User has 1-to-many relationship with Account. I have generated a ado.net entity data model, and I can create users and accounts, and even link them together. In the database the account.user_id is correctly filled, so theoretically I should be able to acces User.Account.ToList() in C# through entity. However, When I try to acces User.Account.ToList() I get zero results. User user = db.User.First(U => U.id == 1); List<Account> accounts = user

How is timezone handled in the lifecycle of an ADO.NET + SQL Server DateTime column?

别说谁变了你拦得住时间么 提交于 2020-01-13 11:27:13
问题 Using SQL Server 2008. This is a really junior question and I could really use some elaborate information, but the information on Google seems to dance around the topic quite a bit and it would be nice if there was some detailed elaboration on how this works... Let's say I have a datetime column and in ADO.NET I set it to DateTime.UtcNow. 1) Does SQL Server store DateTime.UtcNow accordingly, or does it offset it again based on the timezone of where the server is installed, and then return it

Canceling DataAdapter.Fill()

自闭症网瘾萝莉.ら 提交于 2020-01-13 10:26:31
问题 Scenario: We have a DataGridView which is attached to DataAdapter (datatable), we load the data in datatable using (adapter.fill(query, datatable)) in a separate thread (using delegate and beginInvoke) and once the data is loaded we attached that datatable to datagridview (in the main thread) Is there a way we can check if fill() is still executing and cancel it. Real scenario: User click on the user name and corresponding data is loaded in the datagrid. Sometime, user is impatient and click

Detecting unusable pooled SqlConnections

随声附和 提交于 2020-01-13 06:57:49
问题 When I attempt to set an application role on a SqlConnection with sp_setapprole I sometimes get the following error in the Windows event log... The connection has been dropped because the principal that opened it subsequently assumed a new security context, and then tried to reset the connection under its impersonated security context. This scenario is not supported. See "Impersonation Overview" in Books Online.) ... and a matching exception is thrown in my application. These are pooled

Binding a wpf listview to a Dataset…Possible..?

人走茶凉 提交于 2020-01-13 04:15:29
问题 I was struggling moving to Wpf,I am just stuck while trying out databinding to a lsitview.I want to databind a listview to a dataset(dataset because the data i want to display in columns belongs to different tables).I am attaching a sample code that i am trying with.It works alright but the listliew only shows one row.What could be wrong.Can anyone guide me through.All the samples available are using datatables.None specifies about binding to a dataset.Pls help..any input will be highly

How to Insert Rows to Table Object Inside an Excel Sheet?

自作多情 提交于 2020-01-12 12:56:49
问题 I have difficulties trying to insert rows into an existing table object. Here is my code snippet: string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + @"C:\myExcelFile.xlsx" + ";Extended Properties=\"Excel 12.0;ReadOnly=False;HDR=Yes;\""; using (OleDbConnection conn = new OleDbConnection(connectionString)) { conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; string insertQuery = String.Format("Insert into [{0}$] (ID, Title,NTV_DB, Type ) values

How to Insert Rows to Table Object Inside an Excel Sheet?

懵懂的女人 提交于 2020-01-12 12:55:55
问题 I have difficulties trying to insert rows into an existing table object. Here is my code snippet: string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + @"C:\myExcelFile.xlsx" + ";Extended Properties=\"Excel 12.0;ReadOnly=False;HDR=Yes;\""; using (OleDbConnection conn = new OleDbConnection(connectionString)) { conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; string insertQuery = String.Format("Insert into [{0}$] (ID, Title,NTV_DB, Type ) values

How to get the exact type of numeric columns incl. scale and precision?

孤街浪徒 提交于 2020-01-12 07:50:11
问题 Is there a way to know the exact type of a column in a DataTable ? Right now I am doing this: DataTable st = dataReader.GetSchemaTable(); foreach (DataColumn col in st.Columns) { var type = col.DataType; } Now with type.Name I am able to find if it is a number( int or decimal ..) or string but the problem is that I need the exact type, for example if in database let say column Rate is NUMBER(4,3) then here in my code I am only getting type as 'Decimal' and no information about the Format 4,3

F# and ADO.NET - idiomatic F#

為{幸葍}努か 提交于 2020-01-12 02:43:10
问题 I'm just starting to learn F#. I wrote this F#/ADO.NET code last night. In what ways would you improve the syntax - make it feel like idiomatic F#? let cn = new OleDbConnection(cnstr) let sql = "SELECT * FROM People" let da = new OleDbDataAdapter(new OleDbCommand(sql, cn)) let ds = new DataSet() cn.Open() let i = da.Fill(ds) let rowCol = ds.Tables.[0].Rows let rowCount = rowCol.Count printfn "%A" rowCount for i in 0 .. (rowCount - 1) do let row:DataRow = rowCol.[i] printfn "%A" row.["LastName