Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please, guys, I have some problem connecting to my SQL SEVRVER Compact 3.5 database.
The connection string i copied from the "Add data sources" tab shows some errors. The connection string is
Data Source=C:\Documents and Settings\Hp\My Documents\Visual Studio 2008\Projects\Electionsoft\Electionsoft\electionsoft.sdf;Persist Security Info=True.

I wish to access the individual cells in the database. For example, to proceed with the application you need a password which is stored in one cell of the database table named "password"; the same applies to changing the password from the administrator form. "Please someone help me figure this out.
Posted
Updated 17-May-11 22:05pm
v2

1 solution

At a guess, you are doign something along the lines of:
SqlCEConnection con = new SqlCEConnection("Data Source=C:\Documents and Settings\Hp\My Documents\Visual Studio 2008\Projects\Electionsoft\Electionsoft\electionsoft.sdf;Persist Security Info=True.");
And the compiler is complaining?

Try inserting a '@' character in front of the string:
SqlCEConnection con = new SqlCEConnection(@"Data Source=C:\Documents and Settings\Hp\My Documents\Visual Studio 2008\Projects\Electionsoft\Electionsoft\electionsoft.sdf;Persist Security Info=True.");
This disables escape sequence processing, and lets the '\' character through.

If that isn't the problem, then what error are you getting?

By the way: you should never store passwords in clear text. There is a brief tip here explaining why and what to actually do: Password Storage: How to do it.[^]


"this worked thanks, but another thing showed up. I've manually added data to the password database but on trying to retrieve it using
openConnection();
SqlCeCommand cmd;
string command;

try
{
    command = "SELECT main_password FROM password WHERE id = 1";
    cmd = new SqlCeCommand(command,con);
    cmd.CommandType = CommandType.Text;
    SqlCeResultSet result = cmd.ExecuteResultSet(ResultSetOptions.Updatable);
    passwordtxt = result.GetString(1);
    if(passwordtxt.Equals(null))
    {
        command = "SELECT default_password FROM password WHERE id = 1";
        cmd = new SqlCeCommand(command, con);
        cmd.CommandType = CommandType.Text;
        SqlCeResultSet result2 = cmd.ExecuteResultSet(ResultSetOptions.None);
        passwordtxt = result2.GetString(1);
    }
}
catch(SqlCeException sqlException)
{
    MessageBox.Show(sqlException.Message,"Problem1",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message,"Problem2",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
I got the exception that "No data exits for row/column".
please is there something i'm missing. thanks


Really you should open this as a new question.

But: I wouldn't do it that way:
SqlCEConnection con = new SqlCEConnectin(@"Data Source=C:\Documents and Settings\Hp\My Documents\Visual Studio 2008\Projects\Electionsoft\Electionsoft\electionsoft.sdf;Persist Security Info=True.");
con.Open();
SqlCeCommand cmd = new SqlCECommand("SELECT main_password, default_password FROM password WHERE id = 1", con);
try
    {
    SqlCEDataReader r = com.ExecuteQuery();
    if (r.Read())
        {
        passwordText = (string) r.Rows[0]["main_password"];
        }
    if (string.IsNullOrEmpty(passwordText))
        {
        {
        passwordText = (string) r.Rows[0]["default_password"];
        }
    }
catch(SqlCeException sqlException)
    {
    MessageBox.Show(sqlException.Message,"Problem1",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
catch(Exception ex)
    {
    MessageBox.Show(ex.Message,"Problem2",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
finally
    {
    con.Close();
    com.Dispose();
    con.Dispose();
    }
 
Share this answer
 
v2
Comments
Emejulu JVT 18-May-11 5:00am    
this worked thanks, but another thing showed up. I've manually added data to the password database but on trying to retrieve it using

openConnection();
SqlCeCommand cmd;
string command;

try
{
command = "SELECT main_password FROM password WHERE id = 1";
cmd = new SqlCeCommand(command,con);
cmd.CommandType = CommandType.Text;
SqlCeResultSet result = cmd.ExecuteResultSet(ResultSetOptions.Updatable);

passwordtxt = result.GetString(1);

if(passwordtxt.Equals(null))
{
command = "SELECT default_password FROM password WHERE id = 1";
cmd = new SqlCeCommand(command, con);
cmd.CommandType = CommandType.Text;
SqlCeResultSet result2 = cmd.ExecuteResultSet(ResultSetOptions.None);
passwordtxt = result2.GetString(1);
}
}
catch(SqlCeException sqlException)
{
MessageBox.Show(sqlException.Message,"Problem1",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Problem2",MessageBoxButtons.OK,MessageBoxIcon.Information);
}

I got the exception that "No data exits for row/column".
please is there something i'm missing. thanks
Emejulu JVT 18-May-11 5:22am    
do u mean

SqlCEDataReader r = com.ExecuteQuery();

OR

SqlCEDataReader r = cmd.ExecuteQuery();
OriginalGriff 18-May-11 5:25am    
cmd
Sorry - I typed it in a rush! :blush:
Emejulu JVT 18-May-11 5:30am    
Thanks a million times; you have given me some hope with this code. Thanks
Mahmoud 55 25-Nov-12 8:30am    
i submit this code but a have error
this message : Unable to load DLL 'sqlceme30.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900