Need a very small (one table) database!!!

Discussion in 'ASP .Net' started by S_K, Apr 2, 2008.

  1. S_K

    S_K Guest

    Hi,

    I'm working on a project that requires a small database. I'm thinking
    an .MDF database.
    However, I'm having a problem with connecting to the database. The
    code I have is:

    string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=C:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";

    OleDbConnection objConnection = new
    OleDbConnection(strConnection);
    objConnection.Open();

    OleDbDataAdapter adapter = new OleDbDataAdapter("select FName,
    LName from Address", objConnection);
    DataSet ds = new DataSet();

    adapter.Fill(ds, "Address");

    I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    \App_Data\AddressBook.mdf' OleDbExcption when I run it.
    Any ideas?

    Thanks in advance.
    S_K, Apr 2, 2008
    #1
    1. Advertising

  2. S_K

    clintonG Guest

    If you only need one table and no relational model you should reconsider the
    use of an XML file.


    "S_K" <> wrote in message
    news:...
    > Hi,
    >
    > I'm working on a project that requires a small database. I'm thinking
    > an .MDF database.
    > However, I'm having a problem with connecting to the database. The
    > code I have is:
    >
    > string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";
    >
    > OleDbConnection objConnection = new
    > OleDbConnection(strConnection);
    > objConnection.Open();
    >
    > OleDbDataAdapter adapter = new OleDbDataAdapter("select FName,
    > LName from Address", objConnection);
    > DataSet ds = new DataSet();
    >
    > adapter.Fill(ds, "Address");
    >
    > I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    > \App_Data\AddressBook.mdf' OleDbExcption when I run it.
    > Any ideas?
    >
    > Thanks in advance.
    clintonG, Apr 2, 2008
    #2
    1. Advertising

  3. S_K

    clintonG Guest

    Forgot to mention you're using the wrong provider. The .mdf file created
    with SQL Express requires the SQL provider.

    "S_K" <> wrote in message
    news:...
    > Hi,
    >
    > I'm working on a project that requires a small database. I'm thinking
    > an .MDF database.
    > However, I'm having a problem with connecting to the database. The
    > code I have is:
    >
    > string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";
    >
    > OleDbConnection objConnection = new
    > OleDbConnection(strConnection);
    > objConnection.Open();
    >
    > OleDbDataAdapter adapter = new OleDbDataAdapter("select FName,
    > LName from Address", objConnection);
    > DataSet ds = new DataSet();
    >
    > adapter.Fill(ds, "Address");
    >
    > I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    > \App_Data\AddressBook.mdf' OleDbExcption when I run it.
    > Any ideas?
    >
    > Thanks in advance.
    clintonG, Apr 2, 2008
    #3
  4. S_K

    Norman Yuan Guest

    *.mdf is data file used by SQL Server/Express. It is soly accessed by SQL
    Server, you cannot directly access it with your code. Yoou must have SQL
    Server/Express installed in order to make *.mdf file useful.

    You can use Jet database (*.mdb) file, which is file base database, without
    need to have MS Access installed. YOu can also look into SQL Server CE, also
    file based database and very small footprint. Yes, SQL Server CE is mainly
    for mobile device (hence, small fot print) and can also be used for desktop
    application.

    "S_K" <> wrote in message
    news:...
    > Hi,
    >
    > I'm working on a project that requires a small database. I'm thinking
    > an .MDF database.
    > However, I'm having a problem with connecting to the database. The
    > code I have is:
    >
    > string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";
    >
    > OleDbConnection objConnection = new
    > OleDbConnection(strConnection);
    > objConnection.Open();
    >
    > OleDbDataAdapter adapter = new OleDbDataAdapter("select FName,
    > LName from Address", objConnection);
    > DataSet ds = new DataSet();
    >
    > adapter.Fill(ds, "Address");
    >
    > I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    > \App_Data\AddressBook.mdf' OleDbExcption when I run it.
    > Any ideas?
    >
    > Thanks in advance.
    Norman Yuan, Apr 2, 2008
    #4
  5. "S_K" <> wrote in message
    news:...

    > I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    > \App_Data\AddressBook.mdf' OleDbExcption when I run it.


    Yes, you would...

    > Any ideas?


    You're trying to connect to a SQL Server Express database with the Jet OleDb
    driver... Decide whether you want to use SQL Server Express or Jet, and then
    choose the correct connection string...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Apr 2, 2008
    #5
  6. Consider using either a SQL Server Compact 3.5 file-based database file, or
    another similar file-based embedded database file such as SQLite with the
    ADO.NET SQLite 2.0 provider.
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short Urls & more: http://ittyurl.net


    "S_K" wrote:

    > Hi,
    >
    > I'm working on a project that requires a small database. I'm thinking
    > an .MDF database.
    > However, I'm having a problem with connecting to the database. The
    > code I have is:
    >
    > string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";
    >
    > OleDbConnection objConnection = new
    > OleDbConnection(strConnection);
    > objConnection.Open();
    >
    > OleDbDataAdapter adapter = new OleDbDataAdapter("select FName,
    > LName from Address", objConnection);
    > DataSet ds = new DataSet();
    >
    > adapter.Fill(ds, "Address");
    >
    > I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    > \App_Data\AddressBook.mdf' OleDbExcption when I run it.
    > Any ideas?
    >
    > Thanks in advance.
    >
    Peter Bromberg [C# MVP], Apr 3, 2008
    #6
  7. S_K

    slinky Guest

    I've had great success simply using an XML file like:

    <?xml version="1.0" standalone="yes"?>
    <submission>
    <destination>
    <emailAddress></emailAddress>
    <name>Brian Campbell</name>
    <password>tazmania</password>
    </destination>
    <destination>
    <emailAddress></emailAddress>
    <name>Cheryl Robinson</name>
    <password>ceylon</password>
    </destination>
    </submission>

    I connect and read the XML file to add users, passwords, and email
    addresses like:

    <script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    Using ds As New DataSet()
    ds.ReadXml(Server.MapPath("emailList.xml"))
    txtEmail.DataBind()
    txtName.DataBind()
    txtPassword.DataBind()
    End Using
    End If
    End Sub


    Private Sub btnSubmit_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnSubmit.Click
    Using ds As New DataSet()
    ds.ReadXml(Server.MapPath("emailList.xml"))
    Dim dr As DataRow = ds.Tables(0).NewRow()
    dr("emailAddress") = txtEmail.Text
    dr("name") = txtName.Text
    dr("password") = txtPassword.Text
    ds.Tables(0).Rows.Add(dr)
    ds.WriteXml(Server.MapPath("emailList.xml"))
    Response.Redirect("http://Juggernautical.com/Login.aspx")
    End Using
    End Sub

    </script>

    Then to login I use this:

    <script runat="server">


    Private Sub btnLogin_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnLogin.Click
    Dim name As String = txtName.Text
    Dim password As String = txtPassword.Text
    Using ds As New DataSet()
    ds.ReadXml(Server.MapPath("emailList.xml"))
    Dim DataTable As DataTable = ds.Tables(0)
    Dim rows() As DataRow = DataTable.Select("Name = '" & name
    & "' And Password = '" & password & "'")
    If rows.Length < 1 Then
    Response.Redirect("http://mysite.com/
    Unauthorized.aspx")
    Else

    Response.Redirect("http://mysite.com/MembersArea/
    Default.aspx")
    End If
    End Using
    End Sub


    Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Response.Redirect("http://mysite.com/EmailAddressEntry.aspx")
    End Sub

    </script>

    Hope this sparks some ideas. When I need a quick small database I use
    XML files.


    On Apr 2, 4:56 pm, S_K <> wrote:
    > Hi,
    >
    > I'm working on a project that requires a small database. I'm thinking
    > an .MDF database.
    > However, I'm having a problem with connecting to the database. The
    > code I have is:
    >
    > string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";
    >
    >     OleDbConnection objConnection = new
    > OleDbConnection(strConnection);
    >     objConnection.Open();
    >
    >     OleDbDataAdapter adapter = new OleDbDataAdapter("select FName,
    > LName from Address", objConnection);
    >     DataSet ds = new DataSet();
    >
    >     adapter.Fill(ds, "Address");
    >
    > I get an 'Unrecognized database format 'C:\Inetpub\wwwroot\Use Tax
    > \App_Data\AddressBook.mdf' OleDbExcption when I run it.
    > Any ideas?
    >
    > Thanks in advance.
    slinky, Apr 3, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    443
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,580
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    404
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    490
    Dave Thompson
    Feb 14, 2005
  5. ericnoonan
    Replies:
    0
    Views:
    330
    ericnoonan
    Dec 14, 2009
Loading...

Share This Page