Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
I wrote an election application using SQL server compact 3.5 in C#. it works fine in my system but when I Deployed it and installed it on another system, it generates a database problem. It could not connect to the database. I use windows XP SP2. Please can someone help me with some solution.
Posted

Wow, that is a very vague description...

1. Do you have a specific connection error?
2. Does the machine with your application running on have access to the database? Can it see it?
3. Is the database set up with correct settings? (permissions, users etc.)
4. Can you connect to the database via another tool such as a UDL file (create a new file called test.udl and then open the file for some options)
 
Share this answer
 
Comments
Emejulu JVT 12-Jul-11 7:00am    
I'm using Sql compact server so I don't really understand the permission issue. The error is what I caught during the coding.


try
{
openConnection();
string command = "SELECT main_title FROM election_title WHERE id = 1";
SqlCeCommand cmd = new SqlCeCommand(command, con);
SqlCeDataReader r = cmd.ExecuteReader();
while (r.Read())
{
title = r.GetString(0);
}
con.Close();
}
catch (SqlCeException sql)
{
MessageBox.Show(sql.Message, "Title upload error SQL", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Title upload error exp", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

if (title.Equals("Welcome") || title.Equals(" "))
{
try
{
openConnection();
string command = "SELECT default_title FROM election_title WHERE id = 1";
SqlCeCommand cmd = new SqlCeCommand(command, con);
SqlCeDataReader r = cmd.ExecuteReader();
while (r.Read())
{
title = r.GetString(0);
}
con.Close();
}
catch (SqlCeException sql)
{
MessageBox.Show(sql.Message, "Default title upload error SQL", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, " Default title upload error exp", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

label2.Text = title;

try
{
player = new SoundPlayer(@"C:\Program Files\Electionsoft\Santorini.wav");
player.PlayLooping();
}
catch (FileLoadException)
{
//program keeps running without sound
}
catch (FileNotFoundException)
{
//program keeps running without sound
}
}

private static string connectionString()
{
string conString = @"Data Source=|DataDirectory|\electionsoft.sdf;Password=emejulu.4190;Persist Security Info=True";
return conString;
}

private void openConnection()
{
if(con.State == ConnectionState.Closed)
con.Open();
}
musefan 12-Jul-11 7:34am    
You have some really bad code practises going on there!

Firstly, you should definitely be using an app.config file for your connection string.

Secondly, there are a lot of wasted functions floating around. However, it is beyond the scope of this message to go into those :P

Can you check your database connection using the UDL file I had suggested and see if your hard-coded connection string is working...

http://msdn.microsoft.com/en-us/library/e38h511e(v=vs.71).aspx
musefan 12-Jul-11 7:35am    
Also, you should have put this code in your original question using the Edit feature
Some design tips.
Put your connection variables (Host, database name, username etc) in an app.config file.
If you haven't already done so strip the connection logic out of your application entirely.
Code your application's main module to read app.config and pass the connection variables to a new assembly with a name like GetDBConnection
GetDBConnection will have all the logic to make a database connection and will return the connection details to the application's main module.
The main module will then pass this connection as a parameter to any other assembly that needs it.

Further examine your design with a view to doing all database specific work in dedicated assemblies. If you have to change databases in future then the impact is ringfenced into a few specific areas with little or no (if the design is sufficiently robust) knock on effect on the primary functionality of you application
 
Share this answer
 
v2
You need to fix your connection string. I hope your app is well written enough that you can edit it ? If it can't connect, the DB is not there, or the connection string is wrong.
 
Share this answer
 
Comments
Emejulu JVT 12-Jul-11 6:52am    
The connection string is
private static string connectionString()
{
string conString = @"Data Source=|DataDirectory|\electionsoft.sdf;Password=emejulu.4190;Persist Security Info=True";
return conString;
}
and i packaged the installer with the database.

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