Click here to Skip to main content
15,566,615 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
How to connect to Database file in App_Data folder in ASP.Net for Crystal Reports Database Fields ???

I have made a web project. In that, right clicked the website name in the solution explorer. Then chose add new item - SQL Database. Then a database file named Database.mdf was added to the App_Data folder in the website.

This is the database that I use in the project for each and every information.
On one page, I want to generate a report so as to facilitate printing that info. For this, I have added a crystal report to the website. The report takes one parameter i.e. id. Based on that, the other data in the database's table will be displayed in the report. For this, first we have to select the Database expert to connect to a particular database so that the columns of the selected table are displayed in the Field Explorer of the Crystal Report.
But, I am not getting the way to connect to the Database.mdf file using the Database Expert......
Have selected the OLE DB provider for Sql Server, after that, I dont know what Server, Username, Password, Database name to write. The connection string of the local database file as mentioned in Web.config is:
<add name="ConnectionString" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providername="System.Data.SqlClient" />
Tried using DataSet as DataSource. But, no fields are being displayed on putting condition on Id field to be equal to the parameter(id) passed to it.

Most likely the wizard wont show you correctly the sql server instance so instead of selecting it from the combo, write the instance to the field: .\SQLEXPRESS

The Crystal isn't capable of attaching the db (as far as I know) so first manually attach the database to the instance using management studio.

After that check the integrated security check box and now you should be able to see the attached db.
Share this answer
The problem is that the OLE DB provider for sQL Server cannot is obviusly for SQL Server, not Access. That's why it asks a server name, username, pwd, db name.
You need to select a provider for an access DB.

Share this answer
Tech Code Freak 5-Apr-11 10:08am    
My Database file is of SQL Server only and not of Access.
You can see that in the web.config snapshot.
luisnike19 5-Apr-11 10:11am    
Sorry I misunderstood. Did you add any column from the column field to the report?
Tech Code Freak 5-Apr-11 10:19am    
I'm afraid not.
The database columns dont appear in the field explorer as there is no connection.

While using dataset, I've added columns to report. But, on running the page, the data doesnt appear and also there is no error message.

Plz help.
luisnike19 5-Apr-11 14:55pm    
Ok, you need to attach your DB to SQL Server. I suppose you don't do this.
You need to have a SQL Server instance. With this you will know the servername, pwd, user. etc.
And then you will be able to connect to the sql provider.
The web.config here, it's independent here.

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