dbconnection

DbConnection without Db using in-memory DataSet (or similar) as source

丶灬走出姿态 提交于 2019-11-30 07:32:43
问题 I'm trying to unit test a few .NET classes that (for good design reasons) require DbConnections to do their work. For these tests, I have certain data in memory to give as input to these classes. That in-memory data could be easily expressed as a DataTable (or a DataSet that contains that DataTable), but if another class were more appropriate I could use it. If I were somehow magically able to get a DbConnection that represented a connection to the in-memory data, then I could construct my

Right query to get the current number of connections in a PostgreSQL DB

馋奶兔 提交于 2019-11-29 18:55:46
Which of the following two is more accurate? select numbackends from pg_stat_database; select count(*) from pg_stat_activity; Magnus Hagander Those two requires aren't equivalent. The equivalent version of the first one would be: SELECT sum(numbackends) FROM pg_stat_database; In that case, I would expect that version to be slightly faster than the second one, simply because it has fewer rows to count. But you are not likely going to be able to measure a difference. Both queries are based on exactly the same data, so they will be equally accurate. The following query is very helpful select *

DbConnection without Db using in-memory DataSet (or similar) as source

落爺英雄遲暮 提交于 2019-11-29 04:26:07
I'm trying to unit test a few .NET classes that (for good design reasons) require DbConnections to do their work. For these tests, I have certain data in memory to give as input to these classes. That in-memory data could be easily expressed as a DataTable (or a DataSet that contains that DataTable), but if another class were more appropriate I could use it. If I were somehow magically able to get a DbConnection that represented a connection to the in-memory data, then I could construct my objects, have them execute their queries against the in-memory data, and ensure that their output matched

C# Retrieving correct DbConnection object by connection string

本秂侑毒 提交于 2019-11-28 23:14:57
问题 I have a connection string being passed to a function, and I need to create a DbConnection based object (i.e. SQLConnection, OracleConnection, OLEDbConnection etc) based on this string. Is there any inbuilt functionality to do this, or any 3rd party libraries to assist. We are not necessarily building this connection string, so we cannot rely on a format the string is written in to determine its type, and I would prefer not to have to code up all combinations and permutations of possible

Is there any need to close a DbConnection if a using clause is used? [duplicate]

天涯浪子 提交于 2019-11-28 07:30:06
问题 Possible Duplicate: Will a using block close a database connection? Is db.Close() unnecessary in the following? using (DbConnection db = GetDbConnection()) { // do data-access stuff // ... db.Close(); } 回答1: Is there any need to close a DbConnection if a using clause is used? No, there is no need to close a DbConnection if a using clause is used? and Yes it is unnecessary in here because when scope of using ends, connection will dispose meaning closing and releasing all memory. Since

How can I hide my password in my C# Connection string?

。_饼干妹妹 提交于 2019-11-27 09:14:31
I have the following connection string: Data Source=Paul-HP\MYDB;Initial Catalog=MyMSDBSQL;Persist Security Info=True;User ID=sa;Password=password (.net webservice) This can obviously be viewed simply by opening up the app.config file and looking at the configuration settings. What I need is a way to make a hacker unable to see the password. But at the same time, leave it customisable so that it can be changed when deployed on another database. You have a number of options - the ones that I am aware of (in order of preference): Use integrated (SSPI) security where you don't need to include a

How can I hide my password in my C# Connection string?

我们两清 提交于 2019-11-27 04:37:56
问题 I have the following connection string: Data Source=Paul-HP\MYDB;Initial Catalog=MyMSDBSQL;Persist Security Info=True;User ID=sa;Password=password (.net webservice) This can obviously be viewed simply by opening up the app.config file and looking at the configuration settings. What I need is a way to make a hacker unable to see the password. But at the same time, leave it customisable so that it can be changed when deployed on another database. 回答1: You have a number of options - the ones

Is java.sql.Connection thread safe?

北战南征 提交于 2019-11-26 01:57:11
To rephrase the question: should I avoid sharing instances of classes which implement java.sql.Connection between different threads? skaffman If the JDBC driver is spec-compliant, then technically yes, the object is thread-safe, but you should avoid sharing connections between threads, since the activity on the connection will mean that only one thread will be able to do anything at a time. You should use a connection pool (like Apache Commons DBCP ) to ensure that each thread gets its own connection. java.sql.Connection is an interface. So, it all depends on the driver's implementation, but

Is java.sql.Connection thread safe?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 01:47:28
问题 To rephrase the question: should I avoid sharing instances of classes which implement java.sql.Connection between different threads? 回答1: If the JDBC driver is spec-compliant, then technically yes, the object is thread-safe, but you should avoid sharing connections between threads, since the activity on the connection will mean that only one thread will be able to do anything at a time. You should use a connection pool (like Apache Commons DBCP) to ensure that each thread gets its own

nodejs mysql Error: Connection lost The server closed the connection

回眸只為那壹抹淺笑 提交于 2019-11-26 01:37:35
问题 when I use node mysql, an error is appear between 12:00 to 2:00 that the TCP connection is shutdown by the server. This is the full message: Error: Connection lost: The server closed the connection. at Protocol.end (/opt/node-v0.10.20-linux-x64/IM/node_modules/mysql/lib/protocol/Protocol.js:73:13) at Socket.onend (stream.js:79:10) at Socket.EventEmitter.emit (events.js:117:20) at _stream_readable.js:920:16 at process._tickCallback (node.js:415:13) There is the solution. However, after I try