Need a very small (one table) database!!!
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 = [at] "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.
Re: Need a very small (one table) database!!!
*.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" <steve_kershaw [at] yahoo.com> wrote in message
news:7d1d4171-5fcb-49bd-a4c2-1dfaa9a9cef2 [at] q27g2000prf.google groups.com...
> 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 = [at] "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.
Re: Need a very small (one table) database!!!
"S_K" <steve_kershaw [at] yahoo.com> wrote in message
news:7d1d4171-5fcb-49bd-a4c2-1dfaa9a9cef2 [at] q27g2000prf.google groups.com...
> 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
RE: Need a very small (one table) database!!!
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 = [at] "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.
>
Re: Need a very small (one table) database!!!
I've had great success simply using an XML file like:
<?xml version=3D"1.0" standalone=3D"yes"?>
<submission>
<destination>
<emailAddress>campbellbrian2001 [at] yahoo.com</emailAddress>
<name>Brian Campbell</name>
<password>tazmania</password>
</destination>
<destination>
<emailAddress>robinsoncheryl [at] hotmail.com</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=3D"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 =3D ds.Tables(0).NewRow()
dr("emailAddress") =3D txtEmail.Text
dr("name") =3D txtName.Text
dr("password") =3D 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=3D"server">
Private Sub btnLogin_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnLogin.Click
Dim name As String =3D txtName.Text
Dim password As String =3D txtPassword.Text
Using ds As New DataSet()
ds.ReadXml(Server.MapPath("emailList.xml"))
Dim DataTable As DataTable =3D ds.Tables(0)
Dim rows() As DataRow =3D DataTable.Select("Name =3D '" & name
& "' And Password =3D '" & 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=A0pm, S_K <steve_kers... [at] yahoo.com> 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 =3D [at] "Provider=3DMicrosoft.Jet.OLEDB.4.0;Data
> Source=3DC:\Inetpub\wwwroot\Use Tax\App_Data\AddressBook.mdf";
>
> =A0 =A0 OleDbConnection objConnection =3D new
> OleDbConnection(strConnection);
> =A0 =A0 objConnection.Open();
>
> =A0 =A0 OleDbDataAdapter adapter =3D new OleDbDataAdapter("select FName,
> LName from Address", objConnection);
> =A0 =A0 DataSet ds =3D new DataSet();
>
> =A0 =A0 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.
Re: Need a very small (one table) database!!!
If you only need one table and no relational model you should reconsider the
use of an XML file.
"S_K" <steve_kershaw [at] yahoo.com> wrote in message
news:7d1d4171-5fcb-49bd-a4c2-1dfaa9a9cef2 [at] q27g2000prf.google groups.com...
> 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 = [at] "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.
Re: Need a very small (one table) database!!!
Forgot to mention you're using the wrong provider. The .mdf file created
with SQL Express requires the SQL provider.
"S_K" <steve_kershaw [at] yahoo.com> wrote in message
news:7d1d4171-5fcb-49bd-a4c2-1dfaa9a9cef2 [at] q27g2000prf.google groups.com...
> 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 = [at] "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.