Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to published my asp.net website with sql server. Now I need to know if there is something to know how to connect sql database with my .aspx file.
In App_Data foleder I put my sql database(.mdf).
Plz help me.
Posted

You have to attach that database to the shared sql server database or create a database in your sql server if using dedicated ip.

For local host, it is well good to have your database in your local sql server.
But while publishing to external url (either shared ir dedicated server), you need to ensure that you have created your database in the shared server or dedicated server.

Note: All shared server does not have sql server. So cross check with your Service Provider.

Hope this helps.
cheers
 
Share this answer
 
You can publish the local mdf file to your target server . The connection string/settings should be changed accordingly. Refer the following on how to do it.

http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/deploying-a-database-cs[^]

Try and revert if stuck somewhere.
Hope this helps
 
Share this answer
 
You can install the "Connector/Net 1.0 (.NET)" from the mysql website:

http://www.mysql.com/downloads/connector/net/

and transfer the MySql.Data.dll, MySql.Data.Entity.dll, and MySql.Web.dll to the bin folder of your project.

Here is the new code that you can use to connect and finaly display your database online.
This works on godaddy:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//Include namespaces for the MySql .Net Connector
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;


namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString =
"Server=####.db.####.####.com; " +
"Port=####; Database=####; Uid=####; Pwd=####;";

//Create a connection object
MySqlConnection mySqlConnection = new MySqlConnection(connectionString);

//Create a connection command
MySqlCommand mySqlCommand = new MySqlCommand("SELECT * FROM mytable", mySqlConnection);

//check the connection state and open it accordingly.
if (mySqlConnection.State == ConnectionState.Closed)
mySqlConnection.Open();

//MySql datareader object to read the stream of rows from SQL Server Database
MySqlDataReader myDataReader = mySqlCommand.ExecuteReader();

//Pass the Sql DataReader object to the DataSource property
//of DataList control to render the list of items.
myDataGrid.DataSource = myDataReader;
myDataGrid.DataBind();

// close the Sql DataReader object
myDataReader.Close();

// check the connection state and close it accordingly.
if (mySqlConnection.State == ConnectionState.Open)
mySqlConnection.Close();

}

}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900