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

S

S_K

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.
 
C

clintonG

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

clintonG

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

Norman Yuan

*.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.
 
M

Mark Rae [MVP]

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...
 
S

slinky

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

<?xml version="1.0" standalone="yes"?>
<submission>
<destination>
<emailAddress>[email protected]</emailAddress>
<name>Brian Campbell</name>
<password>tazmania</password>
</destination>
<destination>
<emailAddress>[email protected]</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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top