Click here to Skip to main content
15,886,789 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I need code for connect a crystal report to c# windows forms. I've tried many coding but its working on my pc, if i try to run in another pc it shows an error message "Failed to open the connection". I am a student and need to solve this issue to submit my project. Can anyone help me to solve this issue.



this is my coding part :

private void Preview_Click(object sender, EventArgs e)
{
SqlConnection cnn;
string connectionString = null;
string sql = null;

connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=trydb_1;Integrated Security=True";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "SELECT ID,pay_id,date,custname,description,chqno,duedate,accname,amount FROM payments";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"D:\Completing\WindowsFormsApplication1\payments11.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
Posted
Comments
Richard Deeming 29-Oct-14 13:26pm    
You have already posted this question[^].

If you want to edit the question, DO NOT re-post it. Use the "Improve question" link at the bottom of your original question.

1 solution

I assume that the DB is hosted on your PC, because you use the localhost server name. Correct me if I'm wrong:

=.\SQLEXPRESS;Initial


In order to make this work on another PC, you have to replace the "." with your computer name or IP address, and off course the other PC needs to be able to "see" your PC.
 
Share this answer
 

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