Connetion not working even when computer has internet [closed] - c#

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed yesterday.
Improve this question
string connStrings = "SERVER=" + textBox1.Text + "; PORT=" + textBox2.Text + ";DATABASE=" + textBox3.Text + ";UID=" + textBox4.Text + ";PASSWORD=" + textBox5.Text + "";
conn = new MySqlConnection();
conn.ConnectionString = connStrings;
conn.Open();
string queryssqwwqqvv = "Select * from softwareids";
MySqlCommand cmdaassavvvxx = new MySqlCommand(queryssqwwqqvv, conn);
MySqlDataReader dataReaderxsdxxaasxx = cmdaassavvvxx.ExecuteReader();
dataReaderxsdxxaasxx.Read();
if (dataReaderxsdxxaasxx.HasRows)
{
conn.Close();
alertboxs.showinfo.textinfo = "Connection Successful";
alertboxs.showalertbox f = new alertboxs.showalertbox();
f.ShowDialog();
alertboxs.showinfo.textinfo = "";
}
else
{
alertboxs.showinfo.textinfo = "Connection Successful";
alertboxs.showalertbox f = new alertboxs.showalertbox();
f.ShowDialog();
alertboxs.showinfo.textinfo = "";
}
for some reason it doesnt work and my computer has internet connection, also connection details are correct and the database table also exist. All i keep getting is "unable to connect to any of the specified mysql hosts".
For some reason if I connect my phones hotspot to my computer then it works but my house broadband internet doesnt.
Is there anyway to force C# application to work with my house broadband Internet?

If your hotspot is working with this connection it means no issue on the coding side but if you restart your or clear the cache of the router (ISP).
Sometimes the ISP change their setting and the application is not unable to connect.
Last we are facing the issue and called ISP they are resolved.
Check the security firewall and try to ping the network of the database server.

Related

Having troubles with a correct connection string

I have been looking around on the internet to find the proper connection string format, but I find different ones all over the place from different topics posted years between. I can't seem to find the right one. I am using a MySQL Database installed as a Windows Service.
Printed here is my Connection String (I removed the Port after this picture was taken and the last semicolon is there but I omitted it accidentally). But I get the following error message:
I get Error 40 from this. Anyone know the actual correct format? I feel stupid for asking haha
EDIT:
As Requested, instantiation Code for the Connection:
StringBuilder sb = new StringBuilder();
sb.Append("Data Source=MySQL;");
sb.Append("Server=" + Server + ";");
sb.Append("Database=" + Database + ";");
sb.Append("UID=" + UserID + ";");
sb.Append("PWD=" + Password + ";");
Console.WriteLine(sb.ToString());
MySqlConnection conn = new MySqlConnection(sb.ToString());
conn.Open();
return conn;
It is searching for an SQL Server, whereas you want it to connect it to a MySQL database. I guess you are using SQLConnection to connect to the database. That will not work.
You need to either use OleDBConnection or MySQLConnection object to connect to a MySQL database.

Is there any difference between connection string for SQL server express and SQL server?

In my application, i make a dynamic connection string:
server = "Server = .\\" + this.comboBoxListInstances.SelectedItem.ToString() + ";";
connectionString = server + attachDatabase + databaseName + "Integrated Security = true";
On my laptop (using SQL server 2008 express), the result is:
// server = "Server = .\\SQLEXPRESS;" (I select SQLEXRESS in comboBox)
// attachDatabase = "AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;"
// databaseName = "Database = DATA;";
// so the conectionString is : "Server = .\\SQLEXPRESS;AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;Database = DATA;Integrated Security = true"
I read registry to find all SQL server Instances and let the user choose which they want.
This conectionString work fine on my laptop and my friend who use SQL server express too. However, when i run my app on another friend's laptop with SQL server 2008 R2 installed, it throws an exception:
It say the connection string is invalid, It is :
"Server = .\\MSSQLSERVER;AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;Database = DATA;Integrated Security = true"
when I try to temporarily disable comboBoxListInstance and use this conectionString
"Server = (local);AttachDbFileName = |DataDirectory|\\Resources\\DT.mdf;Database = DATA;Integrated Security = true"
The app works! So, I think there is a difference between the conection string for SQL server express and SQL server. Is it right? There is a question similar to mine here, and they say that there is no difference. If they are right, what is the problem of my connectionString?
P/S: sorry for my bad grammar
It looks like you just proved that SqlExpress installs its default named instance as "MSSQLSERVER" where as full sql installs an unnamed default instance of blank.
(local) means " .\ " " 127.0.0.1" WHATEVER instance is at 1433.
.MSSQLEXPRESS means explicitly .\MSSQLEXPRESS which may or may not be the (local) default instance.
As An Aside usually the most relevant difference at this point is that regular SQL will install with the ports open and TCP clients ready to go.
SQL Express will only allow local "dev" type of connections until you activate the external ports and client protocols.

C# Connect to MS SQL Server using Active Directory Service Account

I have a stand alone application that works great with a Local user account in MS SQL. When I try to use an active directory service account instead I appear to be running into problems.
It appears Microsoft want's the exe to run as the domain user service account which is not an option for me. Looking at alternatives, one person mentioned having main exe launching a second exe that does the work or having a local windows service.. neither of these are an option either. It feels like this is getting more complex then it needs to be.
Here is an example of the piece of code I am working with:
private void MakeConnection(){
string ServerNM = #"MyServer";
string Database = #"Test01";
string Username = #"testdomain\testuser";
string Password = #"testpass";
string connection_string = "Server=" + ServerNM
+ "; Database=" + Database
+ "; User ID=" + Username
+ "; Password=" + Password
+ "; Max Pool Size= 1000;";
try {
SqlConnection oSqlConnectionTest = new SqlConnection(connection_string);
oSqlConnectionTest.Open();
}catch(Exception oException){
MessageBox.Show("Error: " + oException.ToString());
}
}
Is this a real limitation or am I missing something?
SQL Server does not accept domain accounts in the connection string for security reasons.

How to connect my app to a database

I am trying to connect my app, developed in C# with a SQL Server database.
The program is done! It's a mobile app.
My database is on C:\ProgramFiles\MyAppName\MyDatabase.sdf
My code line is:
SqlConnection conn = new SqlConnection("server =" + iP.Text +"," + port.Text + ";integrated security=false;Initial Catalog=" + DB.Text + ";User ID=" + userName.Text + ";Password=" + Pass.Text + ";Trusted_Connection=False;");
iP.Text = my IP (102.168.XXX.XXX)
port.Text = 49214 or 1433
DB.Text = "MyDatabase.sdf"
userName.Text= "sa"
pass.Text= "MyPass"
But when I try to connect it, the app says:
er.Message = "El servidor SQL Server no existe o se ha denegado el acceso.
My server name is the same that my userName?
The application was made by someone else, I did nothing. But now I have to change some things and make it better. There is no manual
Any idea? I really don't know what to do
You are using Sql Server Compact Edition (SDF file) not Sql Server.
The classes needed to connect to this kind of database are different
SqlCeConnection conn = new SqlCeConnection(......)
The classes for Sql Server cannot parse correctly your connection string and you get the mentioned error. Of course, the classes for Sql Compact Edition require a reference to the appropriate DLL
System.Data.SqlServerCe.dll
and the appropriate using statement at the beginning of your code file
using System.Data.SqlServerCe;
As last note, the connection string for a SQL CE database is simply
"Data Source = MyDatabase.sdf; Password ='<pwd>'"
doesn't seem possible to pass a specific user. See connectionstrings.com

Retrieving Database Compatibility Level - Different Result for Same Server/DB, Different Users

I have the following code to determine a SQL Server database's compatibility level:
Microsoft.SqlServer.Management.Smo.Server server = new Server(myServerName);
if (!server.Databases.Contains(database))
{ throw new ArgumentException("Specified database ('" + myDBName+ "') not found on '" + myServerName + "'"); }
string connstr = string.Format("Data Source={0};" +
"Persist Security Info=False;" +
"User ID={1};" +
"Password={2};Enlist=False;", myServerName, username, password);
server.ConnectionContext.ConnectionString = connstr;
Microsoft.SqlServer.Management.Smo.Database db = server.Databases[myDBName];
DataSet ds = db.ExecuteWithResults(#"select compatibility_level
from sys.databases where name=db_name()");
I have two users, one of which is able to run this code and get the proper value back. Another user runs this code connecting to the same Server/Database with the exact same credentials and the DataSet returned contains no rows.
What could possibly be the difference between the two users that would cause one to get no result back for the same query? Is there a better way to get Database compatibility?
By the way, this code runs/works on SQL Server 2005 through 2012.
Edit: I should have pointed out that myServerName, myDBName, username, and password are always the same--the only difference is the two different Windows users running the code.
I suspect that the user who returns results has the VIEW_ANY_DEFINITON permission granted to his login. Grant this permission to the other user and he should get the results back.

Categories

Resources