Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit is happening now. Discover what's next in customer experience.

Unable to connect to a remote database through ASP. NET ( ASPHostPortal.com Hosting )

Avatar

Level 1

I have a ASP.NET website and an hosting account on asphostportal.com.

I created a SQL Server Database with Direct Access and updated the connection string with the one provided by asphostportal

There are no errors, but I see no data being stored in the database on a form submit.

Code to insert a row is as follows:


public int run_sql(string msg)

{

    SqlConnection conn = new SqlConnection();

    SqlCommand cmd = new SqlCommand();

    SqlDataAdapter da = new SqlDataAdapter();

    DataSet ds = new DataSet();

    conn.ConnectionString = connString;

    cmd = conn.CreateCommand();

    cmd.CommandText = msg;

    conn.Open();

    cmd.ExecuteNonQuery();

    conn.Close();

    return 1;

}

What could be the issue?

2 Replies

Avatar

Not applicable

What I think is we need to open the connection before assigning it to the command. Can you try this code and see whether it works:

public int run_sql(string msg)

{

    SqlConnection conn = new SqlConnection(connString);

    conn.Open();

    SqlCommand cmd = new SqlCommand(msg,conn);

    cmd.ExecuteNonQuery();

    conn.Close();

    return 1;

}

Hope it works.

Regards