locked
godaddy hosting account and sql server RRS feed

  • Question

  • User837007623 posted

    im trying to access a godaddy sql database using the dql server provided with the hosting package.  im having trouble adding the correct code to make the connection to the database in the web.config file. 

     

    please explain the correct sntax needed for the connection string

     

     

    below is the connection string i have and how i have it configured using the details in the godaddy "SQL Server Database Information" window

      <connectionStrings>

     

    <add name="SaveNewService" connectionString=" Data Source=Host Name; Initial Catalog=Database Name; User ID=User Name; Password=password" />

    </connectionStrings>

     

    and here is my class that uses the string

    using

    System.Data.SqlClient;


    namespace

    MyButler.Secure

    {

       

    public partial class RequestService : System.Web.UI.Page

        {

           

    public static SqlConnection SavenewService

            {

               

    get

                {

                   

    // This property returns a new SQLConnection object when needed

                   

    return new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ButlerData.mdf;Integrated Security=True;User Instance=True");

                }

            }

     

           

    public static void SaveNewService(string username, string Subject, string Details, double Price)

            {

               

    // Add your data access code here

               

    string Sql;

                Sql =

    "INSERT INTO ServiceRequest (UserName, Subject, Details, Price) VALUES (@UserName, @subject, @Details, @Price)";

               

    SqlCommand command = new SqlCommand(Sql, SavenewService);

                command.Parameters.AddWithValue(

    "@UserName", username);

                command.Parameters.AddWithValue(

    "@Subject", Subject);

                command.Parameters.AddWithValue(

    "@Details", Details);

                command.Parameters.AddWithValue(

    "@Price", Price);

     

                command.Connection.Open();

                command.ExecuteNonQuery();

                command.Connection.Close();

            }

           

    protected void Button1_Click(object sender, EventArgs e)

            {

               

    RequestService.SaveNewService(Page.User.Identity.Name, SubjectTextBox.Text, DetailsTextBox.Text, double.Parse(PriceTextBox.Text));

            }

     

    Saturday, February 4, 2012 9:26 PM

Answers

  • User13169337 posted

    hello,

    You can contact your hosting provider and ask them about the correct connection string. :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2012 9:50 PM
  • User3866881 posted

    Hello thelong:)

    1)You can open Vs and "View"=>"Server Explorer" and then create a connection to the specific database,and then copy the Connection String from the right-down property panel。

    2)See this for help:

    http://www.connectionstrings.com/sql-server-2008

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2012 9:00 PM

All replies

  • User13169337 posted

    hello,

    You can contact your hosting provider and ask them about the correct connection string. :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2012 9:50 PM
  • User3866881 posted

    Hello thelong:)

    1)You can open Vs and "View"=>"Server Explorer" and then create a connection to the specific database,and then copy the Connection String from the right-down property panel。

    2)See this for help:

    http://www.connectionstrings.com/sql-server-2008

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2012 9:00 PM