Database error in classic ASP application - asp-classic

I have a classic ASP app which connects to an access database, I receive the following error when I try to access a page which connects to the database:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x1b48 Thread 0x1970 DBC 0x1948024 Jet'.
/gasket.inc, line 24
Here is my gasket.inc file:
<%
'include file for gasket table database object
'Dimension variables
Dim adoConG 'Database Connection Variable
Dim strConG 'Holds the Database driver and the path and name of the database
Dim rsGasket 'Database Recordset Variable
Dim strAccessDBG 'Holds the Access Database Name
Dim strSQLG 'Database query sring
'Initialise the strAccessDB variable with the name of the Access Database
strAccessDBG = "\\MyServer\databases\gaskets\gaskets.mdb"
'Create a connection object
Set adoConG = Server.CreateObject("ADODB.Connection")
'Database connection info and driver
strConG = "DRIVER={Microsoft Access Driver (*.mdb)};uid=admin;pwd=; DBQ=" & strAccessDBG
'Set an active connection to the Connection object
'adoConG.Open "DSN=Gaskets"
adoConG.Open strConG
'Create a recordset object
Set rsGasket = Server.CreateObject("ADODB.Recordset")
%>
Does that admin user require permission to access the database? Or am I missing something else which is obvious?

If you're using a UID/PWD for this, that would have to match an account that was used to lock the database, or a machine/domain account that will have write to/lock permissions to the db. Also, keep in mind that classic ASP is running under the IUSR_ account by default - sometimes this account must have write access to the directory/file containing the Access db.

Related

loop throught data in DSN connection

I set Netsuite (our business management program) up for web service and ODBC connection.
I configure the ODBC in my server to connect to their web service via system DSN and file DSN. I tested the connection with user id and password and it worked.
But now in my VS2013 my ASP.net (VB) page, I can't get to loop through the records in any table:
Dim cn As OdbcConnection
cn = New OdbcConnection("DRIVER=CData ODBC Driver for NetSuite 2015;dsn=odbc1;uid=myemail.com;pwd=mypassword")
cn.Open()
Dim cmdstring33 As String = "select * from CustomList"
Dim cmd33 As New OdbcCommand(cmdstring33, cn)
Dim rds33 = cmd33.ExecuteReader
'While rds33.Read
' Response.Write(rds33("Internalid"))
'End While
cn.Close()
But i get the following error:
ERROR [HY000] An account must be specified in order to login to NetSuite.
in "Dim rds33 = cmd33.ExecuteReader"
But the account works when I test the connection in ODBC administration window
what am I doing wrong?
Thanks for any advice
With the ODBC .NET Managed Provider, you should either specify the DSN you wish to use:
cn = New OdbcConnection("DSN=odbc1")
OR you should specify the ODBC Driver and the connection string:
cn = New OdbcConnection("DRIVER=CData ODBC Driver for NetSuite 2015;accountid=...;password=*****;roleid=3;user=...;version=2013_1")
where you fill in the connection string values based on the documentation provided for the Driver.
*Note that our Drivers (CData software) don't require user/password by default, so you don't need to specify the uid or password when using a DSN.

SQL Login fails from web application for one stored procedure call

Fortunately, this is in UAT rather than production.
The UAT servers are Azure VMs running SQL Server 2012 and Windows Server 2012.
On one page in the application I get an error
Login failed for user 'User'. at System.Data.SqlClient.SqlInternalConnection
Microsoft.ApplicationBlocks.Data.SqlHelperParameterCache.GetSpParameterSetInternal(SqlConnection connection, String spName, Boolean includeReturnValueParameter)
at Microsoft.ApplicationBlocks.Data.SqlHelperParameterCache.GetSpParameterSet(String connectionString, String spName, Boolean includeReturnValueParameter)
at Microsoft.ApplicationBlocks.Data.SqlHelperParameterCache.GetSpParameterSet(String connectionString, String spName)
The login is a SQL Server login, not a domain login
On the SAME web page, there are 3 other stored procedure calls that are made to the same database with the same connection string prior to this stored procedure begin called
I have dropped and recreated the stored procedure
I have dropped and recreated the database login
The account is a member of a database role that grants it EXECUTE rights on the schema this stored procedure belongs to
If I log into SSMS as this user, I can:
Expand the stored procedure list for the database
Expand the parameter list for the affected stored procedure
Run the affected stored procedure and get the expected results
I have an alternative web server set up on the SQL Server which uses domain logins in the connection string, that runs with no problem. We are trying to deprecate the SQL Server version of the web site.
Can anyone suggest what might be causing this, and how to address it?
Thanks you .NET SqlClient security behaviour.
Working call via Data Application block
return SqlHelper.ExecuteReader(ConnectionString, sql_OutboundQueue_TypeAndStatusCount, DBUtility.GetNull(since));
This chains down to calling SqlHelperParameterCache.GetSpParameterSet
Failing call via Data Application block
SqlConnection con = new SqlConnection(QueueDataProvider.ConnectionString);
SqlCommand cmd = new SqlCommand(QueueDataProvider.OutboundQueue.sql_OutboundQueue_Search, con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(SqlHelperParameterCache.GetSpParameterSet(con.ConnectionString, cmd.CommandText));
Reason:
con.ConnectionString has the password cleared if you are using SQL Logins, but only AFTER you call con.Open
Thanks to: ConnectionString loses password after connection.Open

User Instance in a connection string gives an error

When program is trying to open the database I get:
Error message: Cannot open database "Chinatowndb" requested by the login. The login failed.
Login failed for user 'Lee-VAIO\Lee'.
Code is for connection string:
conn = new SqlConnection(#"Data Source=.\SQLEXPRESS;Initial Catalog=Chinatowndb;Integrated Security=True;User Instance=True");
If I change the code to:
conn = new SqlConnection(#"Data Source=.\SQLEXPRESS;Initial Catalog=Chinatowndb;Integrated Security=True");
It works. Now I have another program that uses the first connection string, different database, and it works. Note that the another program has the .mdf file with the App_Data folder. Chinatowndb.mdf is store at C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA.
Why the error?
For mdf database you must change string connection format, it's not same
Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
Or
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
Link :
first one will work if you do this
Go to Query Window in SQL Server Management Studio and type this:
exec sp_configure 'user instances enabled', 1.
Go
Reconfigure
Also Read below
Using an User Instance on a local SQL Server Express instance
The User Instance functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer.
Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;
To use the User Instance functionality you need to enable it on the SQL Server. This is done by executing the following command: sp_configure 'user instances enabled', '1'. To disable the functionality execute sp_configure 'user instances enabled', '0'.
In my case, I excluded the database.mdf file from project, deleted the AttachDatabase:database.mdf from connection string and set user instance=false.
Working fine for me. Able to get data from Database.

Cannot open database 'dbname' requested by the login. The login failed

Firstly, I know that there are a lot of similar topics, but none seem to solve my problem.
I have inherited a project where the front-end is built in ASP.NET and the CMS is built in classic ASP. I'm in the process of setting up a local development environment where I've copied the database from the live server and am configuring the website to connect to my new local DB.
The ASP.NET part is connecting with the connection string Data Source=.\\SQLEXPRESS; Database=DBNAME; Trusted_Connection=True; but I had to mess about with Application Pools and Permissions.
I'm having a problem with getting the classic ASP part of the website to connect to the SQL database. The error I am recieving is:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "DBNAME" requested by the login. The login failed.
/cms/connections/Conn.asp, line 18
The code in that file is:
12. Dim Conn_STRING, URL, mailHost
13. Conn_STRING = "Driver={SQL Server}; Server=.\SQLEXPRESS; Database=DBNAME; Trusted_Connection=True;"
15. Dim conn
16. set conn = Server.CreateObject("ADODB.Connection")
17. conn.ConnectionString = Conn_STRING
18. conn.Open
I know it's a permission problem or some sort, but I can't get to the bottom of it. I'll appreciate any help at all :)
hmmmm, well, the asp.net part is using SQLExpress, connected via an attached file. DBNAME in the first example is going to refer to a db file name in the actual asp.net project. It's been quite a long time since I last used classic ASP, but I'd be STUNNED if it supports this. You need to attach the db file to an actual sql server and use it that way.
server=mycomputername\sqlexpress; database=DBNAME; user id=username; password=password
You'll need to open your database in sql express mngmt studio
http://www.microsoft.com/download/en/details.aspx?id=7593
Go into your security settings for that user and set the default database to "dbname" (whatver your real dbname is of course)
Ensure your app pool is set to run under the user that has permissions to that database. It may just be easier to enable mixed mode authentication and create a sql user to connect to the database rather than messing around with windows authentication on an app pool.
You wil lof course need to change your connection string then to support the sql authentication if you go that route.
http://msdn.microsoft.com/en-us/library/ms143705%28v=sql.90%29.aspx

Why do I get an ADO connection error while using classic ASP?

I am getting an error when running this classic asp script:
Dim DB_CONNECTIONSTRING, rs, iRecordCount, strSQL
DB_CONNECTIONSTRING = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=employee;Trusted_Connection=yes;"
strSQL = "SELECT * FROM EmployeeProfiles"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, DB_CONNECTIONSTRING, adOpenStatic, adLockReadOnly, adCmdText
The message I am getting is (the server does exsist):
Microsoft OLE DB Provider for SQL
Server error '80004005'
[DBNETLIB][ConnectionOpen
(Connect()).]SQL Server does not exist
or access denied.
\Default.asp, line 13
I see you're using Trusted_Connection=yes in your connection string. That means that whatever identity ASP is running under will try to connect to the database server using Windows authentication. The actual identity the web server uses depends on the platform and setup (usually IUSR_Foo).
To test out if this is the issue, try using temporarily replacing the connection string with one that uses SQL authentication. If this is the issue, you may want to either configure the web server to run the ASP under a different user account which has been granted database access (preferred) or give the current web server's identity access to the database. Or you can stick with SQL authentication, of course.
Either the server you're running the ASP on doesn't have a running database server, or the database server should have an instance name. One common mistake is to forget to add the SQLEXPRESS instance name for SQLExpress installs.

Resources