Add Application Name / Program Name in mysql connection string [closed] - c#

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).

Related

sql connection optimization [closed]

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.

Get data from remote sql server in a .NET web service [closed]

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 6 years ago.
Improve this question
I have created a simple web service in visual studio 2015 with C#. I have set up an sql server database with a table and i want to simply return any value from that table.
By searching i haven't found a very explanatory tutorial.
Should i add a server connection in VS and then use linq or use SqlConnection?
I also included an ADO Entity data model in the project but i don't know how to use it in the webMethod.
Does any good tutorial exist about all options that i have to connect to the db and provide some examples, too?
Since it's a web application I suggest saving the connection string into web.config.
Example:
<connectionStrings>
<add name="ConnStringNameHere" connectionString="Data Source=IPadress;Initial Catalog=databaseName;Integrated Security=False;User ID=name;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
You just have to add the user in SQL Server with the appropriate permissions.
That way you can have a couple of connection strings, each for a user type with specific permissions (some can only read, some can write, etc.)
You make a connection to the database with this simple code:
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connStringName"].ConnectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM user WHERE userName = username", connection))
{
connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string id = (string)reader["Id"].ToString();
//work here
}
}
connection.Close();
}
And a useful link: http://www.codeproject.com/Articles/837599/Using-Csharp-to-connect-to-and-query-from-a-SQL-da

c# sql connection through internet [closed]

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.

Accessing sql server data into SparkCLR [closed]

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 7 years ago.
Improve this question
How data can be fetched from SQL Server in SparkCLR?
You could use the following SparkCLR code as a reference to use C# for loading Spark DataFrame from the data in SQL Server, Azure SQL Database or any other JDBC compliant datasource.
//C# sample to load SQL Server data as Spark DataFrame using JDBC
var sparkConf = new SparkConf();
var sparkContext = new SparkContext(sparkConf);
var sqlContext = new SqlContext(sparkContext);
var dataFrame = sqlContext.Read()
.Jdbc("jdbc:sqlserver://localhost:1433;databaseName=Temp;;integratedSecurity=true;", "xyz",
new Dictionary<string, string>());
dataFrame.ShowSchema();
var rowCount = dataFrame.Count();
Console.WriteLine("Row count is " + rowCount);
Few things to note:
This sample code uses Microsoft JDBC driver. If you use a different driver or JDBC datasource you need to update the url
You need to include the driver jar file when submitting your SparkCLR job
SparkCLR project for this sample is available # https://github.com/Microsoft/SparkCLR/tree/master/examples/JdbcDataFrame
My recommendation is to use JDBC to connect to sql server then query against the Dataframe.

Connecting Database using c# in Visual Studio 2013 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a problem connecting my database (created in SQL Server 2008 R2 Express) with c# in vs 2013
Here is the code I wrote
string connStr = ConfigurationManager.ConnectionStrings["newSchool"].ToString();
SqlConnection conn = new SqlConnection(connStr);
the error is NullReferenceException
Change this:
string connStr = ConfigurationManager.ConnectionStrings["newSchool"].ToString();
to...
string connStr = ConfigurationManager.ConnectionStrings["newSchool"].ConnectionString;
Cheers -
Where did you define your connection string? In the app.config? Please send us the place where you configure this.
See http://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx for help.
See http://www.connectionstrings.com/ how to configure a connection string for .net
I assume that there is no connection string named newSchool. It is probably NewSchool or some other casing.
In response to your comment: You need to provide a proper connection string. The ConfigurationManager is used to get a value from the configuration. The NullReferenceException shows you that the setting you request is not there.
You need to create a connection string first using the settings manager and then you can access it.

Categories