AccessDataSource control reports unrecognizable database - asp.net

I am running visual studio 2012 express for the web and on the page I added an asp dropdown box. I tried to load the source from an access 2007 database using an asp:AccessDataSource object. The wizzard completed fine. when I ran the page in the web, I got am error message telling me that the database was in an unrecognisable format. I googled the problem and found out the visual studio does not know to use the provider Microsoft.ace.oledb.12.0 and that I would need to modify the connection string.
Since I'm not writing the code for this page, and relying on VS's visual interface to generate the code, how do I find the code to modify it? Or do I simply write my own code and not rely on VS to do it for me?

You can use the sample code on the page here to display the connection string that your AccessDataSource is using. Verify that the connection string includes
Provider=Microsoft.ACE.OLEDB.12.0;
and the path to the Data source is valid.
FWIW, I just tried to recreate your issue under Visual Web Developer 2010 Express with an Access 2010 database and it worked just fine for me. I also couldn't find any evidence that the connection string for the AccessDataSource was actually "written down" anywhere, in Web.config or elsewhere.

According to this blog entry:
AccessDataSource control
The more I consider it, the more pointless this control seems to me. The only good thing about it is that it works. However, it only works for the .mdb format, as it invokes the Jet Provider internally, and this cannot be changed. You cannot use it with password protected file, as it automatically generates the Connection string from the location of the .mdb file, which you feed to the DataFile property
Thus I will either have to work with an .mdb file or generate the code manually. I vote for the manual creation.

Related

Creating a database project with Visual Studio - can't find database after running?

I am following this tutorial (http://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database) in order to create a database-first app with Entity Framework.
I hit "Run" and everything seems to be working, but in the next part of the tutorial (https://www.asp.net/mvc/overview/getting-started/database-first-development/creating-the-web-application), when I try to add a connection, it's not in the drop-down menu in the "Connection Properties" box under "Select or enter a database name".
Which server is the database on? I didn't specify anything about the server when I created the project for the first tutorial, and I figured that it would be on the default LocalDB that comes with Visual Studio (server name: (localdb)\MSSQLLocalDB), but the database isn't there. Any ideas where I should look or what to try?
Maybe use . (a dot) as Server Name?
Open your Web.config file and check your <connectionStrings> this is where the data source of the database will be. As shown:
However, which version of SQL Server do you have? As this can determine what the correct connection string will be.
Hit Windows+R. And run the following:
%LOCALAPPDATA%\Microsoft\Microsoft SQL Server Local DB\Instances
You may have multiple instances, it would be worth checking each one. So it would be:
(localdb)(name of instance)
This article may also be of use to you:
http://rajchel.pl/2015/10/solving-connection-issue-with-sql-server-2014-localdb/
What could be the case is that you have to run the application you created, and then do something to touch the database like creating / registering a user. After registration you can find the database on the specified location in your web.config settings. This was the solution in my case.

Entity Framework 5 code first - where is the database created

I am following along this tutorial! everything works great, the blog names saved and retrieved from the database (assuming) since they are displayed in the console. Yet there I don't find any database created for it in local db nor the sql express on my machine. How to find where is the database created in the code first approach.
You can get the connection string by using ctx.Database.Connection.ConnectionString which will tell you what database you are using.
I was having a very similar problem here. My connection string was set to .\SQLEXPRESS and a generated Initial Catalog name, but when I connected to .\SQLEXPRESS using SSMS, nothing showed up.
Using IntelliTrace in VS 2010, I was able to see the ADO.NET command, and in the Autos grid, it showed me the SQL command and the following connection string: Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|(my_context_name_here).mdf. Then, using the Server Explorer I can connect to (localdb) and see the data.
This problem happened because my context was derived from DbContext, but it did not used the base(connectionStringName) constructor (like the UsersContext that comes with the MVC4 template does). Changing that, I can see the database in .\SQLEXPRESS.

ADODB recordset error "Operation is not allowed when the object is open" (3705)

I have a legacy ASP application that I support. By support I mean that I haven't touched it since about 2005 because its just worked.
However there were a couple of data issues in the Access database that the ASP application uses. So like a fool I opened the database directly over a fileshare (using MS Access 2007), fixed the data and saved it down (in Access 2000 format).
Now the application will retrieve and display the data OK, but any updates fail with the error 3705: Operation is not allowed when the object is open. I have not changed the code in any way, the only change was the data update and database save.
I've found plenty of examples of this error, but they all relate to fairly simple issues like ensuring the recordset is closed before opening it, changing the CursorLocation enum, etc. I've tried most of these in the vain hope that something will work, but nothing has.
Any ideas how can I fix this?
Thanks.
UPDATE
I've installed a web based access database management system, and have tried to compact and repair the database. I received the error:
The Microsoft Jet database engine cannot open the file '<snip>'. It is
already opened exclusively by another user, or you need permission to view
its data. (-2147217911)
I have run the macro detailed here to determine who is logged onto the database, and just showed the admin user (which was me - while running it)
Those errors mean one thing: the database file is opened by some other process and thus is being locked.
Most likely that "web based access database management system" is the culprit, try to find how you can configure it to not lock the file, or get rid of it.
As a work around or way to verify the real problem, you can copy the .mdb file into different location and change the classic ASP connection string to check if you can update the database in its new location.
#Remou's comment above about checking the file and folder permissions was correct.
I had our server admin check the permissions, and it seems that the write access had dropped off the folder (and the files also inherit their permissions from the folder). He said that this has happened before when saving directly over the fileshare.
(accepting in lieu of an answer from #Remou)

Crystal Reports Viewer: Failed to Open the Connection error

Currently I'm working on a piece of code that involves using the Crystal Reports Viewer to export .RPT files to PDF. My problem is that the code works on literally everything except the website I'm planning to eventually put it on.
When placed on the website it throws back the error "Failed to open the connection." which I believe is connected to the SQL Server connection that's formed in order to read data for the report itself.
The code itself is solid and works when used in a separate console application I built to test it whether said code is run on my local machine or on the server itself. It even runs when I test the website in Visual Studio's virtual host.
I've narrowed it down to being some sort of permissions issue, but I am not knowledgeable enough in the various permissions settings to figure out which ones specifically apply to this situation. It's worth mentioning that other pages on the website are directly connecting to the same database, but they are doing so directly through Linq instead of going through the Crystal Report Viewer.
So does anybody know which settings I need to modify in order to fix the connection error.
An added note: One of the other suggestions is to make sure there's an ODBC DNS in place that matches the one being used by the code. I have created such a DNS already.
Application Pool dictates how your application runs in many ways. You can probably configure the web.config to run under the credentials, or access level of your choice.
Solution for people who didn't read the comments:
Change the identity under the advanced setting's of your application pool to the desired level of access.
Glad I could help.- J

Uploading A SQL Server Script?

My over all goal is to upload a very simple ASP.NET web site created in C# and using a SQLEXPRESS DB to a hosting provider via FTP.
I understand that I can get all of my ASPX, .CS, master pages and image files with no problem. Problem I am having and reason I am here is because I cant simply pop my MDF file into my hosting provider's (Verio Hosting) site.
On the web I ran across a post by Scott Gu. In his post he wrote about converting a MDF into a .SQL file which you can execute from a web site. See below....
If your hoster has no usable HTML web
admin tool for allowing you to easily
manage your SQL database, then you can
also just write a simple ASP.NET page
that you FTP (along with your .SQL
file) to your web-site and then hit to
read the .SQL file on the server in as
text, and then pass it as a string to
ADO.NET to execute. This will give
you the same result as the query
analyzer above - and fully create your
database for you.
I created the .SQL file and I am capable of popping this .SQL file into my website. My question to you guys is how do I create that simple ASP.NET page that I can then hit to read, and then do everything else that Scott mentioned in the passage above????
EDIT: I found out that that I can just re-create my DB by remotely logging in to my hosting providers SQL server via SQL Mgt Studio. I dont want to do this for two reasons 1.) It feels cheap knowing that there is a much cooler way to do this, and 2.) I dont know how to re-create the ASPNETDB.MDF that I use for my user database that ASP.NET created for me.
My question to you guys is how do I
create that simple ASP.NET page that I
can then hit to read, and then do
everything else that Scott mentioned
in the passage above????
Which part of the process don't you understand?
It's just a regular *.aspx web form; you do all of the work in the code behind.
BTW, when sending commands to SQL Server via ADO.NET, keep in mind that ADO.NET doesn't understand "GO" statements; if your script contains them, you will either have to parse them out and submit batches accordingly, or arrange to invoke a command-line tool like sqlcmd from your page, if your hosting provider allows it.
You simply need to have the ASP page read in the .SQL file, which is a series of SQL queries to be executed. Loop though the contents of the file, running each query in turn. The queries will create the db schema, insert the data, etc.

Resources