Connection string Error VS to Mysql
-
I want to insert table in db and make connection to mysql to vs. Error for below code is: System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null. using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Windows.Forms; using System.Data; using System.Drawing; using System.Threading.Tasks; using System.Data.SqlClient; private void button6_Click(object sender, EventArgs e) { string id = textBox6.Text; string name = textBox7.Text; string salary = textBox8.Text; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; string query = "INSERT INTO employee VALUES(@employee_id, @employee_name, @employee_salary)"; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { cmd.Parameters.AddWithValue("@employee_id", id); cmd.Parameters.AddWithValue("@employee_name", name); cmd.Parameters.AddWithValue("@employee_salary", salary); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } Error for below code is: System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)' private void button8_Click(object sender, EventArgs e) { { string connetionString; SqlConnection cnn; connetionString = @"Data Source=LAPTOP-NDOAR92R;Initial Catalog=testDB;User ID=root;Password=mysql"; cnn = new SqlConnection(connetionString); cnn.Open(); MessageBox.Show("Connection Open!"); cnn.Close(); } }
-
I want to insert table in db and make connection to mysql to vs. Error for below code is: System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null. using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Windows.Forms; using System.Data; using System.Drawing; using System.Threading.Tasks; using System.Data.SqlClient; private void button6_Click(object sender, EventArgs e) { string id = textBox6.Text; string name = textBox7.Text; string salary = textBox8.Text; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; string query = "INSERT INTO employee VALUES(@employee_id, @employee_name, @employee_salary)"; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { cmd.Parameters.AddWithValue("@employee_id", id); cmd.Parameters.AddWithValue("@employee_name", name); cmd.Parameters.AddWithValue("@employee_salary", salary); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } Error for below code is: System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)' private void button8_Click(object sender, EventArgs e) { { string connetionString; SqlConnection cnn; connetionString = @"Data Source=LAPTOP-NDOAR92R;Initial Catalog=testDB;User ID=root;Password=mysql"; cnn = new SqlConnection(connetionString); cnn.Open(); MessageBox.Show("Connection Open!"); cnn.Close(); } }
Read the error message, it is not only explicit, it tells you what to do to fix it:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
This may help: Simple SQL Connection String Creation[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Read the error message, it is not only explicit, it tells you what to do to fix it:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
This may help: Simple SQL Connection String Creation[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
ok sir please tell step procedure i am very new to it. i don't know to correct it please help me
-
ok sir please tell step procedure i am very new to it. i don't know to correct it please help me
- DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously. 2) How do you expect me to tell you that step by step, given that I can't see your screen, access your HDD, or have a browse around your network? Did you read the link I gave you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
- DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously. 2) How do you expect me to tell you that step by step, given that I can't see your screen, access your HDD, or have a browse around your network? Did you read the link I gave you?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
I don't understand that link sir, please send some more article pages
-
I don't understand that link sir, please send some more article pages
What part did you not understand? Let's take the instructions one by one...
Quote:
Create an empty text file somewhere on your hard disk, called "myfile.udl".
Have you done that?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
What part did you not understand? Let's take the instructions one by one...
Quote:
Create an empty text file somewhere on your hard disk, called "myfile.udl".
Have you done that?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Created sir this is the location sir D:\Official\ASP.NET\Projects\Basic After that what i have to do sir?
-
Created sir this is the location sir D:\Official\ASP.NET\Projects\Basic After that what i have to do sir?
The link gives teh next instruction:
Quote:
Double click the file, and the "Data Link Properties" dialog will open:
Did you do that? Do you get where I am going with this? Or do I need to copy and paste the whole Tip sentence by sentence as a separate reply to check you have done it?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
The link gives teh next instruction:
Quote:
Double click the file, and the "Data Link Properties" dialog will open:
Did you do that? Do you get where I am going with this? Or do I need to copy and paste the whole Tip sentence by sentence as a separate reply to check you have done it?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
ok sir data link properties opened and i clicked test connection it shows error like Test connection faile because of an error initializing provider invalid authorization specification then what i have to do now sir?
-
ok sir data link properties opened and i clicked test connection it shows error like Test connection faile because of an error initializing provider invalid authorization specification then what i have to do now sir?
Did you follow the instructions between "open the file" and "press the button"? It's saying that the information you provided for that server / database is not valid: the login name, or password for example. If you filled in the info from your existing connection string, then that's why that failed as well: you aren't authorised under that login. We can't fix that, short of coming round to your place and typing on your keyboard - which would cost you a considerable amount of money in time, flights, hotels, taxis, expenses ... So it's probably a good idea if you find out what your login info should be from the person who installed the DB!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Did you follow the instructions between "open the file" and "press the button"? It's saying that the information you provided for that server / database is not valid: the login name, or password for example. If you filled in the info from your existing connection string, then that's why that failed as well: you aren't authorised under that login. We can't fix that, short of coming round to your place and typing on your keyboard - which would cost you a considerable amount of money in time, flights, hotels, taxis, expenses ... So it's probably a good idea if you find out what your login info should be from the person who installed the DB!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
ok sir i will try with correct username pwd and get back you soon
-
Read the error message, it is not only explicit, it tells you what to do to fix it:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
This may help: Simple SQL Connection String Creation[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
ok sir i will try with correct username pwd and get back you soon
:thumbsup:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
In Datalink properties if i click server name refresh it shows empty only sir. how to bring that there i don't know sir. My userid password is userid is root and pwd is mysql but if i enter that it shows error sir on data link properties.
-
In Datalink properties if i click server name refresh it shows empty only sir. how to bring that there i don't know sir. My userid password is userid is root and pwd is mysql but if i enter that it shows error sir on data link properties.
I am not @OriginalGriff.