Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have two questions about use sql server 2008 in c#.
questions 1 : What is the number of simultaneous query for a connection sql server 2005 in c#?
my connection string is :
Data Source = localhost;database=TaskQueue;Persist Security Info=True;integrated security=SSPI; MultipleActiveResultSets=true; Connection Timeout=0;Pooling=false;
questions 2 : what is Productive lifetime of a connection ? i want to keep open a global connection in the end off runing app and just use for this connection.
Do problems occur with this method?
What is the number of simultaneous query for a connection sql server 2005 in c#?
SQL Server 2005 Standard Edition can support a maximum of 32,767 simultaneous connections.
What is Productive lifetime of a connection ? i want to keep open a global connection in the end off runing app and just use for this connection. Do problems occur with this method?
SQL Server takes advantage of connection pooling and as such you'll generally want to keep your connections as short-lived as opposed so that they can be returned to the pool after use.
So consider wrapping your SQL calls within a using statement to ensure they are opened, executed, and properly disposed of as opposed to using a global connection that stays open:
using (var connection = new SqlConnection("your-connection-string"))
{
// Do stuff
}
Check Your Connection String
It's worth noting that your existing connection string has pooling explicitly disabled, which won't allow you to take advantage of the built-in connection pooling:
Data Source = ...; Pooling=false;
I'd highly recommend turning this back on unless you absolutely know what you are doing, as otherwise you might experience some unexpected behaviors, orphaned connections, etc.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am searching for a solution to add application name or program name in connection string so that it is visible under "Client Connection" in "MySQL Workbench".
SQL Server : MySql Server 5.6 |
.Net DLL Version : 8.0.11.0 (download from https://dev.mysql.com/downloads/connector/net/8.0.html)
Here is my connection string
private static string myConnectionString = string.Format("server=192.168.2.2;uid={0};pwd={1};database=databse;SslMode
= none;Application Name=My Application;", Username, Password);
The "Program Name" column in MySQL Workbench comes from a program_name connection attribute. The MySQL documentation incorrectly claims that:
MySQL Connector/NET defines these attributes:
_program_name: The client name
This is wrong in two ways: the attribute name has a typo (leading underscore) and the code that sets it was deleted.
There is no way (a connection string setting or otherwise) to set the value of this attribute in MySQL Connector/NET. Furthermore, the connection attributes are part of the initial handshake so there is no way to set them after the connection is established (e.g., in your application code).
If you're willing to change ADO.NET connector libraries, the MySqlConnector library added support for an Application Name connection string option in v0.44.0; this will let you control the connection attribute that's sent to the server (and it will show up in MySQL Workbench).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a question regarding a TCP Connection Class I'm writing.
The Connection Class I already wrote can establish a connection via TCP. It listens and writes to that connection from two different threads. Now I want to improve that class.
I want to establish this connection fully asynchronous so that the connection can be establishes while other things in my application will be prepared.
But I have some other Classes which needs an established connection to work properly. So, my question is, could someone explain me with an little example how I could establish the connection asynchronous with the possibility that an other class starts to work after the connection is established?
My first idea was to fire an event after the TCP Client is connected but then I got in trouble with the fact, that the connection is only fully established if the remote server sends a message back.
After that I got an idea to create a connection state. But now I don't know how to proceed further.
If it's not the way how to use await and async please let me know.
Thanks in advance,
Patrick
Edit:
Thanks for your answers. To clarify things I want to update my post.
As someone requested what I have so far, I posted my source code at GitHub. In Line 46 I set the connection state to Connecting. After the TCP connection is established I change the status to Fetching (L155). Now I have to wait for the message which indicates that the connection is fully ready. After the Message came I expected I set the State to Open (L315) and fire an ConnectionEstablished Event.
Please excuse but I can't post more than 2 links.
My bit into this: instead of using thread blocks; write a Task for the TCP connection with ManualresetEvent. Making the other part of Thread to change their state based on ManualresetEvent. I personally like Task link is -> https://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.110).aspx
over Thread or Threadpool.
Edit: I have written this on notepad today. If it gives any help.
Task t = Task.Run(() =>
{
//do the connection thing
Connection();
connectionDone.Set(); //Manualeventreset connectionDone = new ManualResetEvent(false);
});
try
{
t.Wait();
}
catch (AggregateException ae)
{
//write the exception somewhere
WriteLog("Exception in task: " + ae);
}
finally
{
connectionDone.Reset();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I was wondering if can I connect to sql database from another computer without installing sql server (is this possible). I am creating a c# wpf program that would get and insert data in sql database that is placed in my PC, in all computers where this program is installed using internet. Should I use in connection string my internet IP, or what, because I’m confused?
My connection string
String connString = #"Network Library=dbmssocn;
Network Address=127.0.0.1,1433;
Integrated security=SSPI;
Initial Catalog=db";
Also i forgot to say that i'm new in programing area, and i want to connect to sql database through lan connection
Assuming that your remote database (on your other computer) accepts remote connections, you can accomplish this via a traditional ADO.NET connection or you could use an ORM like Entity Framework to handle the connection.
You can see an example below that takes advantage of the SqlConnection class which does exactly what it's name implies :
using(var sqlConnection = new SqlConnection("Your Connection String"))
{
var query = "Your Query";
using(var sqlCommand = new SqlCommand(query,sqlConnection))
{
sqlConnection.Open();
// Execute your query here using sqlCommand.ExecuteNonQuery()
// or some other execution method
}
}
You would just need to ensure that your actual connection string to target your remote database is correct.
Yes, it is possible. You could use ADO.NET or Entity Framework to accomplish this goal. However, I would recommend setting up a web api on the sever you have hosting the database, which you could call to get/post data. I personally wouldn't hard code any connection strings in the program you plan to deploy to end user workstations. Just call the web api and let your web api talk to the database.
This question already has answers here:
ExecuteReader requires an open and available Connection. The connection's current state is closed
(3 answers)
Closed 8 years ago.
I have a SQL Server 2008 R2 running but when I try to connect to the server via my C# connection string I receive an error. I have no clue of what the problem is!
Here is my connection string:
_msConnection = new SqlConnection("Server=ServerIpAdress;Database=DataBaseName;User Id=NetworkName\\UserName;Password=PW;");
I hope some of you guys can help me?
Have a great day you all!
Id=NetworkName\\UserName
sounds a bit strange, try
Id=username
Also if you can connect to the DB using MS VS, MS SMS or any other likely tools your app can connect passin exactly same paramenters.
Other things to check: Actual user running the app (IIS_USR maybe)
In your SMS or VS you can get the actual connection string being used and just copy past it.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Entity Framework and Connection Pooling
Does EF1 support Connection Pooling? If yes, what we need to do to manage it?
I don't think you need to do anything except to make sure your connection string throughout the application stays the same. .NET will take care of the rest herself.
Connection pooling is supported by EF and it is default. If you want to change it you can alter Pooling parameter in the connection string true or false.
Assuming SQL Server, somewhere underneath the EF code, a SqlConnection is created using a connection string. A pool of connections will be created per connection string.
It should simply work, without any code / config on your side