c# sql connection through internet [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 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.

Related

Retrieve data from database in MYSQL without empty records [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 8 months ago.
This post was edited and submitted for review 2 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
In MySql table have data and also have some empty values in the same row. Now I want to display that data into the user without that empty values. I'm not write any code yet
Welcome to Stack Overflow!
1.
I'm not too familiar with C# winforms, but this post can help you establish a connection to your MySQL database where you can query for specific data.
Code taken from that post:
string myConnectionString = "server=localhost;database=testDB;uid=root;pwd=abc123;";
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(myConnectionString);
try
{
cnn.Open();
MessageBox.Show ("Connection Open!");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Cannot open connection!");
}
}
Data is retrieved from a MySQL database using a specific SQL (or "Structured Query Language"). In order to learn the basic MySQL syntax for queries, I would recommend a turorial like this.
3.
To send a SQL query to your database (via your established connection in Step 1) I would recommend looking at this post that gives an example on how to send a query via C# winforms
Code taken from that post:
public void Select(string filename)
{
string query = "SELECT * FROM banners WHERE file = '"+filename+"'";
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}
Overall, you're missing a few steps inbetween C# winforms and MySQL. Different languages USUALLY have an external library that facilitates: establishing a MySQL connection and launching MySQL queries. After obtaining the data from a MySQL query return, its up to you on how to display it to the user!
Hope this helps :D

Add Application Name / Program Name in mysql connection string [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 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).

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

Jira Integration in C# [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
I am very new to this.So pardon me if I make any mistakes.
I am trying to read the Jira database.I just need to read it.
No write operations will be involved.
I am using C#.From what little I know, I think a connection has to be established with the Jira database using
SqlConnection conn=new SqlConnection(connectionstring);
And then I can read data using SqlReader.I have tried searching through the database and found few links like http://www.codeproject.com/Tips/762516/Connecting-to-Jira-using-Csharp
But I am not being able to understand.Can anyone help me out or direct me to few resources.
In the links that I searched through there are terms like "Rest API" etc. Do I need to know them ?
If you have access to the database, and want to read data that way, that's entirely possible using standard .NET objects, but you'll probably need to be decent at SQL to get the data out that you want.
Here's how you can (try to) access the database:
SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection("YOUR_CONNECTION_STRING_HERE");
SqlCommand cmd = new SqlCommand("select * from whatever_jira_table", conn);
rdr = cmd.ExecuteReader();
//look up how to read from a reader
conn.Close();
conn.Dispose();
Another option is to use a Jira API which it looks like you can get from NuGet through Visual Studio. If you go this route, you need access to the Jira REST API, and it will expose a more friendly (different?) way to access data.
Either way, just go into Visual Studio, make a console app, and start adding code and stepping through with the debugger until thing start making sense.

Categories