is this the correct format for aspdiscount sql string?

Discussion in 'Databases' started by Gord, May 18, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. is this the correct format for aspdiscount sql string:


    /*****************************************************
    <appSettings>
    <add key="ConnectionString" value="Data Source=tcp:sql2k803.discountasp.net;Initial Catalog=SQL2008_99999_MyAccount;User ID=SQL2008_99999_MyUser;Password=MyPassword;" />
    </appSettings>

    /******************************************************

    I have created a sub directory, deployed my app, activated the sub directory but it cannot find the database.


    here is the calling code:

    /******************************************************

    string strConnection = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

    MyQuery = "Select COUNT('ID') AS GlossaryPageCount From glossary";
    -->crashes here --> MyConn.Open();
    SqlCommand cmdGlossaryPage = new SqlCommand(MyQuery, MyConn);
    MyCount = Convert.ToInt32(cmdGlossaryPage.ExecuteScalar());
    GlossaryPageCount = MyCount;
    MyConn.Close();

    /*************************************************************

    any ideas?

    Thanks!
    Gord
     
  2. Hi,
    If you are referring to ASP.NET Sites or Apps with the SQL Conn in the web.config, no.
    Please give some details and I'll try and help.
    All the best,
    Mark
     
  3. This is in an asp.net 2.0 solution

    the url:

    http://www.gamacd.com/robertburns/1_6.aspx

    the robertburns folder has been activated as an application

    I am using Sql Server 2008 on DiscountASP
    I am using Sql Server 2005 locally

    -I backed up the database locally
    -uploaded it to myaccount on DiscountASP
    -restored it - no errors reported
    -tested access using the Query tools in mylittleadmin - access to tables was successful, and all DB objects were visible

    And if this helps: the application does work locally on my system.

    If you need any other details let me know

    Thanks!
    Gord
     
  4. ...You can find webcasts on this sort of thing on the asp.net site in the Learning section.
    If you want I'll create a Webcast using a DASP site.

    To do what you want in Visual Studio is not hard at all.
    What are you using?

    Here's the way it can go in VS:

    1) Your web.config has a connections section where the DB server info from your DASP control panel will go.
    It will look like this:
    <connectionStrings>
    <clear />
    <remove name="LocalSqlServer" />
    <add name="LocalSqlServer" connectionString="Data Source=tcp:sql.discountasp.net;Initial Catalog=SQL_numid_account;User ID=SQL_numid_user;Password=pw_here"
    providerName="System.Data.SqlClient" />
    <add name="SQL2005_msftwise_userConnectionString" connectionString="Data Source=tcp:sql.discountasp.net;Initial Catalog=SQL_numid_account;User ID=SQL_numid_user;Password=pw_here"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    2) Then in VS you can create a DataSet or just drag your DB tables onto the page. That part would look like this:

    <form id="form1" runat="server">
    <div>

    </div>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
    EmptyDataText="There are no data records to display.">
    <Columns>
    <asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID"
    SortExpression="DepartmentID" />
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    <asp:BoundField DataField="GroupName" HeaderText="GroupName"
    SortExpression="GroupName" />
    <asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate"
    SortExpression="ModifiedDate" />
    </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
    ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>"
    SelectCommand="SELECT [DepartmentID], [Name], [GroupName], [ModifiedDate] FROM [Department]">
    </asp:SqlDataSource>
    </form>

    ...Make sense?
    If you need specific help just ask but please mention which tools you'll be using.
    All the best,
    Mark
     
  5. why are there two connecrtion strings?

    <add name="LocalSqlServer" connectionString="Data Source=tcp:sql.discountasp.net;Initial Catalog=SQL_numid_account;User ID=SQL_numid_user;Password=pw_here"
    providerName="System.Data.SqlClient" />

    and

    <add name="SQL2005_msftwise_userConnectionString" connectionString="Data Source=tcp:sql.discountasp.net;Initial Catalog=SQL_numid_account;User ID=SQL_numid_user;Password=pw_here"
    providerName="System.Data.SqlClient" />

    also, is "SQL2005_msftwise_userConnectionString" a string which must be exactly as it is, or can this string be anything?
     
  6. Hi,
    The web.config section allows for some helpful settings, such as Add, Clear and Remove.
    The example I posted shows how to get rid of a common error where LocalSQLServer can be sometimes at fault and by using two strings for the same SQL Server this at first clears out the "possible" error.
    That part is not needed, it's insurance against trouble.

    The next part where is shows msftwise is where in VS you name the actual connection string then use it in your code pages.
    You can give that any name you want.
    I should have named those examples so they matched, was in a bit of a hurry cause my three kids got home from school and are hanging me. ;-)
    All the best,
    Mark
     
  7. Thanks!

    I will keep working on it - enjoy your evening with the kids! :)
     
  8. Doing my best, thx ;-)
     
  9. Still not working :confused::

    web.config:

    <connectionStrings>
    <clear />
    <remove name="ConnectionString" />
    <add name="ConnectionString" connectionString="Data Source=tcp:sql2k803.discountasp.net;Initial Catalog=SQL2008_713283_ME;User ID=SQL2008_713283_Me_user;Password=MyPwd;"
    providerName="System.Data.SqlClient" />
    <add name="ConnectionString" connectionString="Data Source=tcp:sql2k803.discountasp.net;Initial Catalog=SQL2008_713283_ME;User ID=SQL2008_713283_Me_user;Password=MyPwd;"
    providerName="System.Data.SqlClient" />
    </connectionStrings>


    aspxc file:

    namespace DataSourceTests
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    string MyQuery;
    SqlCommand MySqlCommand;

    // Define query to retrieve current page's records
    string strConnection = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
    SqlConnection MyConn = new SqlConnection(strConnection);

    MyQuery = "SELECT Title FROM Poems";
    MySqlCommand = new SqlCommand(MyQuery, MyConn);
    MyConn.Open();

    MyConn.Close();
    MyConn = null;

    }
    }
    }
     
  10. Should be:
    string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    You're currently attempting to read a connection string from the appSettings section of the web.config.

    You're also going to need to do something with MySqlCommand e.g. call ExecuteReader to get the result of the query.
     
  11. Thanks - I will make the changes - wow that was sloppy!

    I did not put and data elements in because I wanted to make the code as simple as possible - as long as it did not crash, I figured I would have moved one step forward.

    Thanks
    Gord
     
  12. Got it!

    Thanks

    Wisemx, and CrystalMS for all your help!
     
  13. ...We very much appreciate feedback...Good job ;-)
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page