Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi guys,
I am not very good in ASP.Net, I developed a website with ASP.Net 2010, i used the default membership provider and it works very well on my Local PC with its defaults configuration and default database(AspNetSql.mdf).
My problem is I dont know how to change this defaults configuration to match my web hosting company configuration.
I created an sql database Through control panel of my website:
server: Enk-sql01.swh.mweb.co.za
Database : AspNetSql
username : User, I gave him all permission
Password:
and the web hosting company they gave me the name of the server: XX-sql01.xx.mweb.co.za and its SQL 2008 R2
Can somebody help me how to configure my website to work with these details?
Thanks
Posted
Updated 11-Jan-13 0:22am
v2

So you just need to know how to build a connection string?

so it would be "Data Source = Enk-sql01.swh.mweb.co.za; User Id = <username you="" gave="">; Password = <password you="" gave="">; Initial Catalog = AspNetSql" would be your connection string

Also, http://www.connectionstrings.com/[^]

Example:

web.config file
<appsettings>
    <!-- [DATABSE SERVER SETTINGS}-->
    <add key="DB_Server" value="Enk-sql01.swh.mweb.co.za" />
    <add key="DB_User" value="Your Username" />
    <add key="DB_Pass" value="Your Password" />
    <add key="DB_Name" value="AspNetSql" />    
  </appsettings>

C#
string ConnectionString = String.Format(@"Data Source = {0};User Id={1}; password={2}; Initial Catalog = {3};",
                            ConfigurationManager.AppSettings["DB_Server"],
                            ConfigurationManager.AppSettings["DB_User"],
                            ConfigurationManager.AppSettings["DB_Pass"],
                            ConfigurationManager.AppSettings["DB_Name"]);

string query = "your query here";

SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
SqlCommand queryCMD = new SqlCommand(query, connection);
SqlDataReader queryReader = queryCMD.ExecuteReader();
while (queryReader.Read())
{
//do your work here
}
 
Share this answer
 
Thanks a lot, it worked. I apreciate.
 
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