Classic ASP Error 80004005 when trying to connect to SQL Server - sql

I am trying to connect a classic ASP webpage to SQL Server 2008, and whatever I do I keep getting this...
error '80004005'
It then proceeds to tell me the line where the error is, and that is all.
My connection code is as follows
<%
Dim Stock
Dim Stock_cmd
Dim Stock_numRows
Set Stock_cmd = Server.CreateObject ("ADODB.Command")
Stock_cmd.ActiveConnection = MM_DVerto_STRING
Stock_cmd.CommandText = "SELECT Location, Part_Number FROM dbo.Stock_Header WHERE Part_Number = ?"
Stock_cmd.Prepared = true
Stock_cmd.Parameters.Append Stock_cmd.CreateParameter("param1", 200, 1, 15, Stock__MMColParam2) ' adVarChar
Set Stock = Stock_cmd.Execute
Stock_numRows = 0
%>
Connection File
<%
' FileName="Connection_odbc_conn_dsn.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="false"
' Catalog=""
' Schema=""
Dim MM_DVerto_STRING
MM_DVerto_STRING = "dsn=CMD SQL;uid=web;"
%>
Any help would be greatly accepted!

Error 80004005 is:
Data source name not found and no default driver specified
Most likely your web server is missing an ODBC connection named CMD SQL.
If not, here is the full list of possible causes from that MSDN link:
The Microsoft Windows NT 4.0 or Windows 2000 user account that is used to process the request for the ASP page does not have sufficient
permissions to read the registry key that stores the specified DSN's
configuration information.
The System ODBC DSN that is specified in the ADO connection string does not exist on the IIS server.
The ASP Application or Session variable that is initialized in the ASP application's Global.asa file (or in an ASP page that is accessed
before the page that contains the database connection code) is used to
specify the ADO connection string. This connection string variable is
not initialized when the code to open the database connection is run.
To confirm this, add a Response.Write statement before the line of
code that opens the database connection to display the connection
string that is stored in the variable.

Related

DSNless connection to Oracle database using DAO Database object in VBA

it's possible to use DSNless connection with wiht an object created from DAO Database class in VBA.
The connection to database using ODBC connection works as expected, however if you use other connection string types as mentioned www.connectionstrings.com the connection is not established.
public Sub dbConnectTest()
Dim myDB As DAO.Database
Dim conn As String
Dim tns As String
Dim odbcString as String
odbcString = "ODBC;DSN=Location Name;UID=ANUSER;PWD=apassword;DBQ=A_TNS_NAME"
' this part works
Set myWorkspace = DBEngine.CreateWorkspace("APPNAME", "admin", "")
Set myDB = myWorkspace.OpenDatabase(Name:="", Options:=dbDriverNoPrompt, ReadOnly:=True, _
Connect:=odbcString)
' same here
Set myDB = OpenDatabase("", False, False, "ODBC")
' any of below part don't work
odbcString = "Driver=(Oracle in XEClient);dbq=server:1980/SID;UID=ANUSER;PWD=apassword;"
odbcString = "Driver={Oracle in OraHome92};Dbq=A_TNS_NAME;UID=ANUSER;PWD=apassword;"
odbcString = "Driver={Microsoft ODBC for Oracle};CONNECTSTRING=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1980)))(CONNECT_DATA=(SERVICE_NAME=SID)));Uid=ANUSER;Pwd=apassword;"
Set myDB = OpenDatabase("", False, False, odbcString)
end sub
I want to change the connection string due to the fact that even if myDB object is set to nothing after a user logout, when a new login is requested with a new password the old connection string is somehow preserved and instead of a connection error a successfully connection object is retrieved.
I was able to connect to an Oracle 11g instance using the following connection string and call to OpenDatabase. I'm using the version of DAO available through the reference "Microsoft Office 16.0 Access database engine Object":
' Construct connection string
oracxnstr = "Driver={Microsoft ODBC for Oracle};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fake.url.com)(PORT=fakePortNo))(CONNECT_DATA=(SID=fakeSID)));Uid=fakeUid;Pwd=fakePw;"
I've obviously used fake parameters in this string so I'm not exposing my database.
' attempt to connect to oracle
Set oradb = dbws.OpenDatabase("", 1, True, oracxnstr)
The Microsoft DAO documentation is woefully inadequate, so I'm pointing out the differences between my code and yours that might be relevant:
I'm using the connection string parameter "Server" instead of "CONNECTSTRING." However, either one works in my system.
I'm using the connection string parameter "SID" instead of "SERVICE_NAME." This also did not make a difference... this time. But for reasons I don't understand, I know that it has made a difference in the past. I don't understand why it does sometimes make a difference. (I'm an Oracle novice but I think the Oracle configuration has something to do with it.)
For the 2nd parameter to the OpenDatabase method, I'm using 1 instead of true. This is the dbDriverNotPrompt enumerated constant. If I change to true, this also doesn't make a difference.
If I use DAO 3.6 I do get a run-time error 3151 "ODBC connection failed." I'm wondering if the older version isn't able to handle DSN-less or TNS-less connection strings to Oracle?
The only other difference I can think of is that maybe your Oracle username/password account has Read Only permissions, while the 3rd parameter to the OpenDatabase method is set to false?

Accessing Oracle SQL Developer database from VBA

New to VBA and returning to SQL after 15 years. I'm am trying to use VBA to run SQL commands to download data into excel for further manipulation.
I have SQL Developer installed on my machine and I am able to access the database using the UI. I have figured out how to connect to the database and run a query within the SQL Developer interface, but honestly, I'm not an IT guy.
Any ideas how to do this? Even basic command line commands to connect to the database and run the query would be helpful.
I found this code on another site, but I'm having trouble getting my connection string to work. My macro errors out on the cnn.Open statement and says the Provider is not installed. I think it's because PROVIDER is set up for a different SQL Database type, but I can't seem to get the connection string to work.
I know my username and password, which I have successfully used to connect in the SQL Developer UI. I'm not sure what to put for remote IP address or database. Would that be the hostname and the SID in the connection properties dialog in SQL Developer? (The hostname looks more like a url without the http than an ip address. Not sure if hostname and ip address is an interchangeable term).
Sub Download_Reports()
'Initializes variables
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String
Dim StrQuery As String
'Setup the connection string for accessing MS SQL database
'Make sure to change:
'1: PASSWORD
'2: USERNAME
'3: REMOTE_IP_ADDRESS
'4: DATABASE
ConnectionString = "Provider=ORAOLEDB.ORACLE;Password=PASSWORD;Persist Security Info=True;User ID=USERNAME;Data Source=REMOTE_IP_ADDRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=DATABASE"
'Opens connection to the database
cnn.Open ConnectionString
'Timeout error in seconds for executing the entire query; this will run for 15 minutes before VBA timesout, but your database might timeout before this value
cnn.CommandTimeout = 900
'This is your actual MS SQL query that you need to run; you should check this query first using a more robust SQL editor (such as HeidiSQL) to ensure your query is valid
StrQuery = "SELECT TOP 10 * FROM tbl_table"
'Performs the actual query
rst.Open StrQuery, cnn
'Dumps all the results from the StrQuery into cell A2 of the first sheet in the active workbook
Sheets(1).Range("A2").CopyFromRecordset rst
End Sub
I'm needing help with my connection string. Can anyone help me with this?
I'm connecting to a database via Oracle SQL Developer. I am able to connect within the UI by providing the following items:
Connection Name - got it.
myUsername - got it.
myPassword - got it.
Connection Type = Basic, Role = default
myHostname - got it.
myPort - got it.
mySID - got it.
However, I am unable to get my connection string to work in VBA. When I run the script I get
"Run-time Error '3076'. Provider cannot be found.
It may not be properly installed" on the line beginning with cnn.open.

Unable to open shared SQLite database

Unable to open database file
That's the error I get when trying to open a SQLite db file that is shared, I've already allowed read/write to everyone when I shared the folder containing the db file.
I'm accessing the file using LINQPad or SQL Server Compact & SQLite Toolbox both gives me the same error.
However I can successfully work with the database using my Windows Form application with the following declaration for the connection
Dim litecon As SQLiteConnection = New SQLiteConnection("Data Source=\\10.10.10.10\SQLite\SQLiteDB.db;Version=3;Password=1;", True)
I set parseViaFramework to True

Cannot open database "ABC" requested by the login. The log in failed

I am using the following code to connect to SQL with VBA and getting the error at the title
' Create a connection object.
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
' Provide the connection string.
Dim dbms As String
Dim strConn As String
' Specify the OLE DB provider.
cnPubs.Provider = "SQLNCLI"
'Set SQLOLEDB connection properties.
cnPubs.Properties("Data Source").Value = Worksheets(1).Range("B3")
cnPubs.Properties("Initial Catalog").Value = Worksheets(1).Range("B4")
' Windows NT authentication.
cnPubs.Properties("Integrated Security").Value = "SSPI"
'Now open the connection.
cnPubs.Open
I didn't have issues before while I was using SQL authentication as I could specify username and password. Now I need to use Windows authentication and I am getting an error.
I think the issue is with the autofill of username when I select Windows authentication
at SQL login. Cross referenced with SQL login page
Server type: Database engine
Servername: Server\Database
Authentication: Windows Authentication
Locked selection:
Username: NT.COMPANY.COM\username
password:
anyone know how I can log in to Server\Database?
The error you are getting can be caused by one of two things:
The database you are trying to open does not exist
The account you are using has not bee granted access to the database
Because you are saying that connecting to the database works with SQL Authentication, you are most likely running into 2. To fix this you need to grant access to that database to your windows login.

Creating a workspace session using SAS IOM & VBA

I am trying to connect to a workspace server using Excel VBA. Using the information on this page, I have produced the following:
Dim obSAS As SAS.Workspace
Dim obWorkspaceManager As New SASWorkspaceManager.WorkspaceManager
Private Sub Form_Load()
Dim obConnection As New ADODB.Connection
Dim obRecordSet As New ADODB.Recordset
Dim obServerDef As New SASWorkspaceManager.ServerDef
Dim xmlString As String
obServerDef.Port = 28561
obServerDef.Protocol = ProtocolBridge
obServerDef.MachineDNSName = "blah.server.com"
Set obSAS = obWorkspaceManager.Workspaces.CreateWorkspaceByServer( "Ref", _
VisibilityProcess, obServerDef, "me#saspw","MyPass", xmlStr)
end sub
My first response was this:
<xml id="combridgeOutput"><connectionAttempts><connectionAttempt>
<sasserver></sasserver>
<sasmachinednsname>blah.server.com</sasmachinednsname>
<sasport>28561</sasport>
<saslogin>me#saspw</saslogin>
<status>0x80041001</status>
<description><Exceptions><Exception>
<SASMessage severity="Error">
The client has connected to a SAS (9.2) Metadata Server (v1.0) when
it intended to connect to a SAS Workspace Server.
</SASMessage>
</Exception></Exceptions></description>
</connectionAttempt></connectionAttempts></xml>
So I updated the port number to point at the workspace server, and now I get this:
<same XML tags as above >
<SASMessage severity="Error">
Client me#saspw does not have permission to use server
SASMeta - Workspace Server (A5DPDN69.AV000069).
</SASMessage>
Would rather not set special permissions for this exercise. How else can one connect VBA to a SAS workspace server session?
Doh! I was using the wrong machine name. For reference, here is the process for getting the correct machine name!
Log into SMC
Expand Server Manager
Expand SASApp
Expand SASApp - Logical Workspace Server
There you will see the correct machine, and will also show the port details..