Con.open error ASP.NET in Godaddy Plesk Hosting - asp.net

I am struggling with my new website which I recently uploaded on Godaddy server.
Con.open() is the line which is causing error : The wait operation timed out
My Code: file.aspx.cs
SqlConnection con = new SqlConnection(#"Data Source=databaseserverurl;Network Library=DBMSSOCN;Initial Catalog=mydatabase;User ID=something;Password=something;");
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
if (con.State != ConnectionState.Open) {
con.Open();
}
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from mytable";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
}

For MySQL
You should use MySqlConnection, not SqlConnection.
For SQL Server
Most likely your databaseserverurl is wrong. Make sure your connection string corresponds to the one you have in the control panel. See https://de.godaddy.com/help/find-your-connection-strings-3323.
To ensure, open Sql Server Management Tool (or your favorite sql tool) and login your db with same server, user and password.

Related

How to refresh a webpage once azure sql database table is updated

I'm working on a webPage app using C# ASP.NET, it retrieves me data from Azure Sql Database once I click my submit button.
protected void BtnSubmit_Click(object sender, EventArgs e)
{
string connStr = "Server=*******";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
string strQuery = "select **** from myTable";
SqlCommand sqlcmd = new SqlCommand(strQuery, conn);
Label1.Text = sqlcmd.ExecuteScalar().ToString();
conn.close();
}
Now I'm trying to get my wabPage label.text updated automatically with the latest uploaded records in Azure Sql Database table, without using clock control, how do I achieve that?

System.InvalidOperationException connecting to SQLExpress database?

protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(#"Data Source= LAPTOP-KVFS4TPD\\SQLEXPRESS; Database= PayPalDB; UID= sa; PWD= 061199081298;");
SqlCommand cmd = new SqlCommand("SP_DBASE", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.AddWithValue("#FirstName", FNtxt.Text);
cmd.Parameters.AddWithValue("#MiddleName", MNtxt.Text);
cmd.Parameters.AddWithValue("#LastName", LNtxt.Text);
cmd.Parameters.AddWithValue("#Email", Emailtxt.Text);
cmd.Parameters.AddWithValue("#Email2", Email2txt.Text);
cmd.Parameters.AddWithValue("#BirthDate", txtDate.Text);
cmd.Parameters.AddWithValue("#Address", Addresstxt.Text);
cmd.Parameters.AddWithValue("#CreditCardNo", CCNtxt.Text);
cmd.Parameters.AddWithValue("#CVVNo", CVVtxt.Text);
cmd.Parameters.AddWithValue("#Gender", GenderRDL.SelectedItem);
cmd.Parameters.AddWithValue("#Country", DDLCountry.SelectedItem);
cmd.ExecuteNonQuery();
con.Close();
Server.Transfer("UserLogIn.aspx", true);
}
enter image description here
The error is in con.Open();:
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code".
Your connection string is wrong.
This is the correct syntax for SQLExpress connection strings:
Data Source=.\SQLEXPRESS;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
In your case:
SqlConnection con = new SqlConnection(#"Data Source=.\SQLEXPRESS;Database=PayPalDB;UID=sa;PWD=061199081298;");

Database is not connected from webconfig file

The below code is during page load event in aspx.cs file. When I load the page in chrome, it throws some error in cs file.
Stack trace error:Network related error while connecting to sql server:
protected void Page_Load(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM employee"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
listviewmain.DataBind();
}
}
}
}
Connection string in web.config file:
<add name="constr"
connectionString = "data source=.;initial catalog=[Analyst_RealEstate_WebCP];persist security info=True;user id=sa;password=pass#word1;multipleactiveresultsets=True;"
providerName="System.Data.SqlClient"/>
Sql Connection :
When I am trying to connect in sql using these credentials, I am able to login but not through web.config file

Fetching data from remote SQL server

I have developed a asp.net web application using visual studio 2010. I'm using SQL server 2008 as database. I need to fetch data from one of the remote server through LAN connection and have to store to my database through C# code. I am beginner to web development using asp.net and C#. please tell me a very simple way to solve this.
This is an example which I tried. Is this code OK or wrong please guide me with this?
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection();
con1.ConnectionString = #"Data Source=172.16.7.127\inhouse;User ID=****;Password= *****;";
con1.Open();
string str = "select * from t_his_events Where patientMRN="+hosp_no.Text;
SqlDataReader dr;
SqlCommand myCommand = new SqlCommand(str,con1);
dr = myCommand.ExecuteReader();
if (dr.HasRows)
{
Console.WriteLine("connection established");
}
}
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection(<connectionstring>);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM table";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
And now you have a DataSet containing the results of your query. As for determining your , I suggest Connection Strings as a great resource for picking the perfect format.
Where is your database name in connectionString you created on remote server
using System.Data.SqlClient;
using system.Data;
string cs = Data Source=172.16.7.127\inhouse;database=databasename;User ID=User id create on remote server;Password= Your password for the ;
SqlConnection conn = new SqlConnection(cs);
SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM tableName",conn);
DataSet ds = new DataSet();
adp.Fill(ds);
now you can use the dataset object that contain your table

I could not connect to database

public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=LENOVO;Initial Catalog=dbMACARON;Integrated Security=True"); SqlCommand com = new SqlCommand("Select * from PRODUCT");
public void Bind()
{
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
con.Open();
com.Connection = con;
com.ExecuteNonQuery();
da.Fill(ds, "PRODUCT");
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
com.Connection = con;
SqlDataReader dr;
dr = com.ExecuteReader();
string id = "0";
Source Error:
Line 31: protected void Page_Load(object sender, EventArgs e)
Line 32: {
Line 33: con.Open();
Line 34: com.Connection = con;
Line 35: SqlDataReader dr;
It said error on my con.Open could not open database, what did i go wrong?
sorry im fresh so i need guidance ,
there some source error it tells me
if you are using sql express edition try this:
SqlConnection con = new SqlConnection("Data Source=.\SQLExpress;Initial Catalog=dbMACARON;Integrated Security=True");
Try using port number with the DB server name
What is the authentication mode? Windows Authentication or User id/Password based?
If it is userId/password based, then you need to provide password also.
Try this as it is.
1. Go to Tools menu-> folder option-> view tab and unCheck the following checkbox with name that HIDE EXTENSION FOR KNWON FILE TYPES.
2.Now crate the file as sql with extension udl i.e sql.udl. It will ask you for confirmation press Yes.
Right click on that file and select open with OLEDB CORE DATASERVICE. It will open the dialog box as follows.
![enter image description here][2]
Go to provider tab and select Microsoft OLEDB PROVIDER FOR SQL SERVER.. AND THEN CLICK ON NEXT BUTTON.
Then copy and paste your server name from SQL SERVER MANAGEMENT STUDIO in the first textbox. on second number select which mode you are using and in the end select the database which you want to use from the dropdown.
Click on TEST CONNECTION button it will show you successfull connection .
finally close that window and now open that udl file with notepad. Copy the content starting from the provider name to the end and paste it into your coding page.
Thats it. It will not show you error again.
I HAVE FIX IT MY SELF!! BUT THANKS FOR EVERYONE FOR TRYING HELPING ME OUT !! THANKS YOU!!
what i do is i put double "\" between lenovo and ebg example in sqp connection..
EXAMPLE:
public partial class SignUp : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=LENOVO\EBG; Initial Catalog=dbMACARON; integrated security= True");
SqlCommand com = new SqlCommand("Select * from CUSTOMER");
public void Bind()
{
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
con.Open();
com.Connection = con;
com.ExecuteNonQuery();
da.Fill(ds, "CUSTOMER");
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
weird in this web it didt show double "\" in here... but nway thanks.

Resources