Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Connect to database
PostPosted: Mon Oct 10, 2011 12:55 am 

Joined: Fri Oct 07, 2011 11:03 am
Posts: 2

Offline
Hi everybody,

I got some difficulties to connect with a database (*.sdf* files).

With Microsoft SQL server 2008, I can open the database and make some SQL request.

So I have tried differents solutions to connect to the database, but I never success.

Have you some solutions or methods to connect to database.

Code:
namespace Neo.ApplicationFramework.Generated
{
   using System;
   using System.Drawing;
   using System.Data;
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Text;
   using System.Windows.Forms;
   using System.Data.SqlClient;
   using System.IO;

    public partial class BACKGROUND
    {
   
      
      void Button6_Click(System.Object sender, System.EventArgs e)
      {
         SqlConnection conn = new SqlConnection("Data Source=C:/Documents and Settings/fabrice/Mes documents/ECO-ENERGIE/ECO_ENERGIE/Temp/Output/Database.sdf;");
         //SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=Database;Integrated Security=SSPI");
         try
         {
            conn.Open();
            MessageBox.Show("Database opened....");
            // Insert code to process data.
            
             SqlCommand cmd = new SqlCommand("select * from ECO_ENERGIE", conn);
         }
         catch (Exception ex)
         {
            MessageBox.Show("Impossible to connect to database");
         }
         finally
         {
            conn.Close();
            MessageBox.Show("Database closed");
         }
      }
      
   }
}


Thank you in advance for your help


 Profile  
 
 Post subject: Re: Connect to database
PostPosted: Mon Oct 10, 2011 9:53 am 
User avatar

Joined: Fri Jul 15, 2011 3:21 pm
Posts: 214

Offline
This directory:

"C:/Documents and Settings/fabrice/Mes documents/ECO-ENERGIE/ECO_ENERGIE/Temp/Output/Database.sdf;");"

Looks like it my be valid for a PC. Are you developing targeting a PC platform or a terminal?

_________________
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer


 Profile  
 
 Post subject: Re: Connect to database
PostPosted: Mon Oct 10, 2011 9:57 am 

Joined: Fri Oct 07, 2011 11:03 am
Posts: 2

Offline
Thank you for your reply.

I'm actually developping on a PC platform.

Maybe, my method is not the right one to connect with the database. Because I look on some websites other way to connect with database in C#.

Thank you.


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron