Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ian 35 posts 135 karma points
    Jul 24, 2013 @ 15:03
    ian
    0

    How to connect to a new database?

    Hi,

    I'm using umbraco v6 (newbie) and VS2012 express. Currently in a localhost dev setup

    I have created a new database and added the connection string (<add name="umbracoGearBox" connectionString="Data Source=|DataDirectory|\gearbox.sdf" providerName="System.Data.SqlServerCe.4.0"/>) to the web.config file. I can access the new database using razor within umbraco. However Using VS2012 c# .net control I can't seem to connect to the database to then query the dataset. I have googled and tried various connection settings but can't seem to get it working?? Surley it can't be that hard? Please help..

     

    many thanks

    ian

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 24, 2013 @ 16:01
    Ismail Mayat
    0

    Ian,

    Can you paste your usercontrol code please. Also which exact version of v6 are you using? Also are you trying to access custom tables in the db or umbraco tables?

    regards

    Ismail

  • ian 35 posts 135 karma points
    Jul 24, 2013 @ 16:24
    ian
    0

    Hi Ismail,

    Thankyou for the reply... I think I have at least got something working..

    I'm using Umbraco v6.0.7. I have created my own custom database called gearbox.sdf, I want to query the table called gearbox and filter out results depending on selections from 3 dynamic dropdown lists. The code below is how far I have got up to now. As long as I'm on the right track I'm sure I can figure out the remaining code..

     

            protected void list1_SelectedIndexChanged(object sender, EventArgs e)

            {

                SqlCeConnection con = new SqlCeConnection(System.Configuration.ConfigurationManager.ConnectionStrings["umbracoGearBox"].ConnectionString);

                con.Open();

                SqlCeCommand command = new SqlCeCommand("SELECT * FROM gearbox", con);  //would query a specific field string here depending on ddlist selection

                SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(command);

                DataSet ds = new DataSet();

                dataAdapter.Fill(ds);

                tester.Text = ds.Tables[0].Rows.Count.ToString(); //display record count found to test

                con.Close();

            }

     

    ian

     

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 24, 2013 @ 18:14
    Ismail Mayat
    100

    Ian,

    In the latest version of umbraco you can use the abstracted data layer that uses peta poco so that does all the work for you. However in your version you can also use the old data layer 

    SqlHelper.ExecuteScalar(GlobalSettings.DbDSN,CommandType.Text,"yourqueryhere"

    proabably want executereader. It is db agnostic so works with sql server and sql ce as far as i am aware.  

    Regards

    Ismail 

  • ian 35 posts 135 karma points
    Jul 25, 2013 @ 10:33
    ian
    0

    thanks Ismail I'll look into it.

     

    ian

Please Sign in or register to post replies

Write your reply to:

Draft