tags:

views:

155

answers:

4

I have developed an application using VB.NET, Visual Studio 2008 and the SQL Server database. Now I want to ignore the database (it has 1 table as customer (name,password,hour,minute)) as I don't want my client to install SQL Server separately or other overheads.

I am planning to do the whole using file handling in VB.NET (manipulating the data in files itself, for example change username, password, etc.). As I am new I don't actually know the proper way and of course need assistance.

+4  A: 

You might want to use SQLLite, which is an in-process DB. You could reuse most of your existing code and your client doesn't have to deal with the overhead of installing SQL Server.

dsolimano
+1 SQL Server CE also fits this description.
Adam Robinson
Agree on Sql Server CE. If you have already started down the Sql Server path, then the code should not change appreciably. In addition, the Eneity Framework works with Sql CE.
Chris Dunaway
thanks...i appreciate ur support
Indranil Mutsuddy
A: 

You do not have to do this using files... You will lose the bascic functionality provided by a db such as simple INSERT/UPDATE/DELETE/QUERY

You could use a simple Database such as MS Access or SQLite

Edit

MS Access Connection string will depend on the version you are using, a little more detail on the possible version of Office/MS Access will help but

MS Access 2007:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;

Prior to MS Access 2007

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

For Ms Access you need to use OleDbConnection Class instead of SqlConnection Class as for Sql Server

astander
i am not aware of access. I tired to do that but has shown some error in provider name
Indranil Mutsuddy
Show us the error you received, and the version of MS Access, and we can try to help.
astander
MS Access 2007, {"Keyword not supported: 'provider'."} is the errorand what is the replacement of thiscode in access Dim con As SqlConnection Dim cmd As New SqlCommand con = New SqlConnection(conn)
Indranil Mutsuddy
No, no. You do not want to recreate your project in MS Access, but purely use it as the database included in the project installer, so as to avoid Sql Server.
astander
i didnot get the point i afraid, Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\INDRANIL\Documents\GameOn.accdbis my conn string
Indranil Mutsuddy
And what does the error state?
astander
the whole thing is working fine with sql server. Now i onle change the connection string to , Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\INDRANIL\Documents\GameOn.accdb and now the error is Keyword not supported: 'provider'." (highlighting yellow on this line con = New SqlConnection(conn))
Indranil Mutsuddy
You cannot use http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(VS.71).aspx to connect to Ms Acces,you need to use http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection(VS.71).aspx
astander
OleDbCommand. is for access right?
Indranil Mutsuddy
Yes, that is what I used X-)
astander
so u want me to replace all my sqlcommd with OleDbCommand?Is there a way if i could talk to you? making my points more clearer?
Indranil Mutsuddy
sure i'll...as of now i am editing the codes
Indranil Mutsuddy
Dim dr As SqlDataReader its in sql ...what is the oleDbCommand?
Indranil Mutsuddy
Have you taken down the address? I wish to delete it as soon as possible...
astander
Have a look at http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader(VS.71).aspx
astander
yes i did...i ve send an invitation
Indranil Mutsuddy
I have not received anything yet, but will be taking it down. Please feel free to contact me here again if I do not respond X-)
astander
sure i'll..Hey its working in access ..jus have a minor bug m looking through it...Could u help mewith deploying the application?
Indranil Mutsuddy
Yes, I will. Let me know what the issue is. Mailing me will be easier as we do not have to clog up the thread...
astander
okay sure i'll thanks for your support
Indranil Mutsuddy
please check ur mail
Indranil Mutsuddy
+1  A: 

Some people prefer to store simple data as XML. Then you can use LINQ or XPath to query the XML. I have also seen others use a strongly-typed DataSet and persist it to the HDD.

tgolisch
A: 

I'm not sure what file format you'd like to use for your flat files, but one easy option is to use XML. You can certainly generate your own format, but there's some easy tooling in VB.Net for reading and writing XML files.

To write an xml file:

Public Sub SaveAs(ByVal fileName As String)
    Dim writer As Xml.XmlWriter
    Dim settings As New Xml.XmlWriterSettings
    settings.Indent = True
    settings.CloseOutput = True
    writer = Xml.XmlWriter.Create(fileName, settings)

    writer.WriteStartElement("customer")

    writer.WriteStartElement("customerName")
    writer.WriteValue("customer #1")
    writer.WriteEndElement()

    writer.WriteEndElement()

    writer.Close()
End Sub

Reading from an XML document you can use some of the inline VB XML language features:

Public Sub Load(ByVal fileName as String)
    If Not IO.File.Exists(fileName) Then Throw New Exception("File not found.")
    Dim xDoc as XDocument

    Try 
        xDoc = XDocument.Load(fileName)
    Catch e as Xml.XmlException
        Throw New FileFormatException()
    End Try

    Dim customers = xDoc..<customer>
    For each customer in customers
        Dim customerName = customer.<customerName>.Value
        //'do something with the data
    Next

End Sub

Beth Massi has some good videos on working with XML files and data in VB

gbc
thanks a lot for ur time. I do appreciate ur support.
Indranil Mutsuddy
You're welcome. If you're new to the site, don't forget to accept one of the provided answers when you feel that it has answered your question.
gbc