sqlconnection

Which pattern is better for SqlConnection object?

本秂侑毒 提交于 2019-12-23 16:28:09
问题 Which pattern is better for SqlConnection object? Which is better in performance? Do you offer any other pattern? class DataAccess1 : IDisposable { private SqlConnection connection; public DataAccess1(string connectionString) { connection = new SqlConnection(connectionString); } public void Execute(string query) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = query; command.CommandType = CommandType.Text; // ... command.Connection.Open(); command

Connection using enlist=false does not close after being manually enlisted in distributed transaction

耗尽温柔 提交于 2019-12-23 15:11:58
问题 I have a distributed transaction context using ServiceDomain . Inside it, I open an SQL connection with connection string specifying Enlist=false , so that it is not automatically enlisted in the transaction. Then, if I manually enlist the connection in the distributed transaction using EnlistDistributedTransaction , the connection does not get closed, which can end in an InvalidOperationException with: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.

Difference between connection.OpenAsync and connection.Open when using Dapper QueryAsync method

余生长醉 提交于 2019-12-23 14:55:34
问题 What is the difference between using connection.OpenAsync() and connection.Open() when using dapper's QueryAsync method. Async: public async Task<IList<Product>> GetListAsync() { using (var connection = new SqlConnection(_connectionString)) { StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT Id, Name "); sql.AppendLine("FROM Product "); await connection.OpenAsync(); var tickets = await connection.QueryAsync<Ticket>(sql.ToString()); return tickets.ToList(); } } Not Async: public

Best practice for reusing SqlConnection

橙三吉。 提交于 2019-12-23 07:15:52
问题 I've come from Java experience and am trying to start with C#. I've read SqlConnection SqlCommand SqlDataReader IDisposable and I can understand that the best practice to connecting to a DB is wrapping SqlConnection , SqlCommand and SqlDataReader in their own using block. But in Java we use to encapsulate the connection into a factory method, create it only once, and reuse it for all queries, even multithreaded ones. Only statements and result sets are created for each query and closed ASAP.

Best practice for reusing SqlConnection

风流意气都作罢 提交于 2019-12-23 07:14:35
问题 I've come from Java experience and am trying to start with C#. I've read SqlConnection SqlCommand SqlDataReader IDisposable and I can understand that the best practice to connecting to a DB is wrapping SqlConnection , SqlCommand and SqlDataReader in their own using block. But in Java we use to encapsulate the connection into a factory method, create it only once, and reuse it for all queries, even multithreaded ones. Only statements and result sets are created for each query and closed ASAP.

How to set binary data using setBlob() in C++ connector

倾然丶 夕夏残阳落幕 提交于 2019-12-23 03:17:10
问题 I know this has been asked before, and I tried to implement the solution, but I just get exception errors when I call ps->executeUpdate(). Has anyone got an explicit example? 回答1: Sorry Matthew - I assumed the previous answer to this question (by elrohin). Maybe I should have replied to that. Anyway heres the code he suggested: class DataBuf : public streambuf { public: DataBuf(char * d, size_t s) { setg(d, d, d + s); } }; // prepare sql update statement etc. and set the data pointer string*

Azure Functions static SqlConnection - right way to scale?

梦想与她 提交于 2019-12-22 10:34:30
问题 I'm using Azure Functions with queue triggers for part of our workload. The specific function queries the database and this creates problems with scaling since the large concurrent number of function instances pinging the db results in maximum allowed number of Azrue DB connections being hit constantly. This article https://docs.microsoft.com/en-us/azure/azure-functions/manage-connections lists HttpClient as one of those resources that should be made static. Should database access also be

Powerbuilder 12.5 database connection beginner tutorials

谁说胖子不能爱 提交于 2019-12-22 00:27:22
问题 I am fairly new to powerbuilder 12.5 and i cant find much tutorials on database management on SQL 2008. I need to connect to it via code like in VB.NET vs2008 Dim con As New SqlConnection Con.connectionstring = "Data Source=servername;Initial Catalog=user;Integrated Security=True" I need to select, insert, update and delete data... Any help on code samples 回答1: Datawindows Most database work with PB is done using datawindows. After you create a new datawindow, you set up your select statement

calling new SqlConnection() hangs program

你离开我真会死。 提交于 2019-12-21 12:16:31
问题 This one has me stumped. I'm not even trying to connect to a database. When this code gets to the line where I instantiate a new SqlConnection object, it just hangs there, not throwing an exception or anything. I've tried compiling it for 2.0. 3.5 and 4.0, and they all hang. Of course it works on my machine and yours, too. But I'm trying to run this code on a Windows Server 2008 x64 server, and it won't budge. // example.cs using System; using System.Data; using System.Data.SqlClient; public

Managing SQL Server Connections

我是研究僧i 提交于 2019-12-21 04:38:06
问题 What is the the best practice for SQL connections? Currently I am using the following: using (SqlConnection sqlConn = new SqlConnection(CONNECTIONSTRING)) { sqlConn.Open(); // DB CODE GOES HERE } I have read that this is a very effective way of doing SQL connections. By default the SQL pooling is active, so how I understand it is that when the using code ends the SqlConnection object is closed and disposed but the actual connection to the DB is put in the SQL connection pool. Am i wrong about