Database connection error with MSSQL 2005 - sql-server-2005

I've got the following code and I'm trying to establish a connection to a data base. I have MSSQL 2005 as the database and trying to connect though ODBC connection.
Importantly I'm trying to use 'Windows authentication' instead of 'SQL authentication' to login to the database. (Note that SQL auth is NOT an option for me!)
<%
Dim Conn
Set Conn = CreateObject("ADODB.Connection")
Dim ConnectionString
Conn.ConnectionString = "Server= CLMSAWN002; Database= mohan_db; Integrated Security=True;"
Conn.Open ConnectionString
Conn.CommandTimeout=120
Sub CloseConn
Conn.Close
Set Conn = Nothing
End Sub
%>
In the live environment I get the following error.
Microsoft OLE DB Service Components error '80040e21'
Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done.
/CustomerMarketing/_db.asp, line 10
Can you help me understand what cause this and a possible solution?

Related

ODBC connection from MS Access to MySQL server fails to execute stored procedure

I just started out with mySQL and need some help here. I have a 10.4.27-MariaDB- Server with a mySQL database. I want to execute several queries from a Microsoft Access document. I have a stored procedure on the server named "task_data_proc". This procedure returns the task data for a given task number. It is working fine on the server. It contains the following code:
BEGIN
SELECT * FROM task_data WHERE TASKNUMBER = uTasknumber;
END
In my VBA-code I tried to call the Procedure via ODBC using ADO:
Private Sub Test()
Dim conn As Object, cmd As Object, rst As Object
Const adCmdStoredProc = 4, adParamInput = 1, adVarInt = 3
Dim asked_number As Integer
'defining random task-number for testing purpose
asked_number = 1200
Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
' DSN-LESS CONNECTION
conn.Open "Driver={MySQL ODBC 8.0 ANSI Driver};host=localhost;database=expert_db;" _
& "UID=root;PWD=generic_password"
' CONFIGURE ADO COMMAND
Set cmd = CreateObject("ADODB.Command")
With cmd
.ActiveConnection = conn
.CommandText = "task_data_proc"
.CommandType = adCmdStoredProc
.CommandTimeout = 15
End With
' APPEND NAMED PARAM
cmd.Parameters.Append cmd.CreateParameter("uTasknumber", adVarInt, _
adParamInput, 6, asked_number)
Set rst = cmd.Execute
' FREE RESOURCES
rst.Close
Set rst = Nothing
Set cmd = Nothing
Set conn = Nothing
End Sub
When I run this I get:
Runtime error '-2147467259 (80004005)':
[MySQL][ODBC 8.0(a) Driver]Access denied for user 'root'#'localhost' (using password: YES)
However I used the same "generic_password" in my code that I use to log into the server with PHPmyAdmin. I tried it without a password as well and I got the same error message, except "(using password: NO)".
I also included the "skip-grant-tables" command in the "my.ini" document for the SQL-Server.
Is the String that I defined for conn.Open incorrect?
I have also tried using a pass-through-query in Access. When I setup the ODBC connection for the pass-through-query I chose the database and hit "Test". It says "connection successful". I hit OK.
The ODBC connection String is then automatically named "ODBC;DSN=unfall;SERVER=localhost;UID=root;PWD={generic_password};DATABASE=expert_db;PORT=3307;COLUMN_SIZE_S32=1;DFLT_BIGINT_BIND_STR=1"
I define the pass-through-query as "SELECT * FROM task_data"
I run the query. It returns the entire table with the task data, as I intended. But if I filter for a specific task number in the table or scroll through the data for a while, suddenly an error pops up:
ODBC-call failed
[MySQL][ODBC 8.0(a) Driver]mysqld-5.5.5-10.4.27-MariaDB
After that message the entire table just contains "#NAME" in every single cell. When I run the query again, the data is back there until I scroll/filter and the message pops up again. Am I using the wrong ODBC driver? Or are pass-through-queries not suitable for select-statements?
I also tried using linked tables with ODBC instead. It worked fine but was quite slow. I wanted to improve the performance by either using pass-through-queries or calling procedures using ADO.
Thank you very much for any help or guidance!

Open ODBC connection from data source Ms Access

I am trying to connect to an ODBC data source that is properly setup and when i run the test connection it works. BUt when migrating my code from DAO to ADO the code sample below gives me an error: cannot connect to mysql server on localhot (10061)
Here is the sample code:
Dim conODBC As New ADODB.Connection
Dim rs As New ADODB.Recordset
conODBC.Open "Driver={MySQL ODBC 5.1 Driver};dsn=SomeDataSource;UID=SomeUserID;"
any ideas what could be causing this?

OLEDB Connection from Excel to Oracle Issue

Everyone,
A VBA problem has been killing me the past two days. I have a Macro Based Model in Excel that has data sets bought into the spreadsheets from Oracle via OLEDB. To illustrate the problem simply I have created two functions within the Model. One using ODBC("odbc") and another using OLEDB("OraOLEDB"). The code was working completely fine last week and it has not been changed.
Now, however I get an error message that states "Run-Time Error '424': Object Required when I execute the line "conn.Open strCon" in sub "OraOLEDB".A connection can't be established with the database! So when I am trying to establish a connection to the database with that line of code, it fails. What is interesting is that via ODBC, a connection can be established. The line "conn.Open strCon" in sub "odbc" executes successfully and I am able to establish a connection to the database.
I did not change anything in the Excel Model but I did have a bunch of windows updates recently. I don't know if that corrupted anything. I think it may have. The reason why I don't want to use the ODBC connection is that it is significantly slower. I get run times 10x faster using OLEDB. Please let me know if you can help.
Sub odbc()
Dim conn As Object
Dim strCon As String
strCon = "Driver={Microsoft ODBC for Oracle};
CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=xxx)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=xxx)));
uid=xxx;pwd=xxx;"
Set conn = CreateObject("ADODB.Connection")
conn.Open strCon
End Sub
Sub OraOLEDB()
Dim conn As Object
Dim strCon As String
strCon = "Provider=OraOLEDB.Oracle;
Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = xxx)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = xxx)));
User Id=xxx;Password=xxx"
Set conn = CreateObject("ADODB.Connection")
conn.Open strCon
I see the host for the OLEDB connection is modn-ast-fdb1. ... while for the ODBC connection you have modn-ast-tdb1. ... Shouldn't the host be the same?
This means Set conn = CreateObject("ADODB.Connection") returns nothing. Check ADODB.dll registration. Alternatively you may use
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
and you'll see if ADODB is available at the moment you edit the script not waiting for runtime errors.

The microsoft access database engine cannot find the input table or query 'dbo'.. (VBA, Access2010)

Helllo!
I'm an MS Access-beginner. After an upgrade from Access2003 to Access2010 I am changing the database connection of our MS Access-Application from ODBCDirect (not supported anymore) to ADODB.
After (hopefully) successfully establishing a DB connection over an ADODB.Connection object I am initializing an ADODB.Command object:
Dim qdfWork As ADODB.Command
...
Set qdfWork = New ADODB.Command
Set qdfWork.ActiveConnection = CurrentProject.Connection
qdfWork.CommandText = "[dbo].[storedProcedureName]"
qdfWork.CommandType = adCmdStoredProc
qdfWork.Parameters.Refresh 'HERE THE ERROR-MESSAGE OCCURS
...
There is a stored procedure with the exactly same name "[dbo].[storedProcedureName]" stored on the server, but I still get the error-message:
"the microsoft access database engine cannot find the input table or query 'dbo'. Make sure it exists and that its name is spelled correctly."
If I don't write "[dbo]" in the CommandText I still get the same message, telling that "[storedProcedureName]" can't be found.
Here is my ADODB.Connection.connectionString:
"Driver={Microsoft Access Driver (*.mdb)};Dbq=\\folder1\folder2\User1\Database.mdb; Uid=Admin;Pwd=password;"
The connection via this connectionString works fine I think, I don't get any error-messages when connecting to the DB.
I checked that CurrentProject.Connection is really the connection I need.
I don't understand why my Application can't find this stored procedure although it is stored on the server.
Thanks for reading

Correct connection string for VB.NET WinForms application connecting to local SQL Server db

I am building a VB.NET WinForms application in VS2013. The program is using a SQL Server 2012 ("Full" version of SQL Server - NOT SQL Express) database that is local to the deployed application - both on the development computer and the computer (the only computer) the program will be used on.
In the program, when the user clicks a button, a sql script - an sql file on the computer - needs to execute.
Depending on the type of connection string I try, I am getting different errors and I'm not sure which connection string to use.
Here is my code:
Private Sub btnLoadMasterData_Click(sender As Object, e As EventArgs) Handles btnLoadMasterData.Click
Dim connString As String = "Server=DHSNET\[dbuser];Database=hours_analysis;User Id=[USERNAME];Password=[PASSWORD]"
'Dim connString As String = "Server=DHSNET\[dbuser];Database=hours_analysis;Integrated Security=True"
'Dim connString As String = "Server=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=C:\[PATHTOFILE]\hours_analysis.mdf"
'Dim connString As String = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\[PATHTOFILE]\hours_analysis.mdf;Integrated Security=True;Connect Timeout=30"
Dim file As New FileInfo("C:\HL_Time_Entry_Reporting\SQL Scripts\stage_employee_hours_load.sql")
Dim sqlText As String = file.OpenText().ReadToEnd()
ExecuteCommand(sqlText, connString)
End Sub
Private Sub ExecuteCommand(queryString As String, connectionString As String)
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(queryString, connection)
command.Connection.Open()
command.ExecuteNonQuery()
End Using
End Sub
As you can see, I've tried several types of connections. The fourth one is what VS2013 set up to connect to the database for the datagridviews in the application, which load and work fine.
I got the other three connection strings from the ConnectionStrings.com "SQL Server 2012 connection strings" page.
When I use the first and second connection strings there is a pause of about five seconds and then a SqlException error occurs on the Connection.Open() line, saying
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
When I use either of the connection strings for the .mdf file I get a SqlException error saying
Database 'hours_analysis' does not exist. Make sure that the name is entered correctly.
(The path to the file is correct)
What connection string to I need to use?
For anyone else that's looking for help on this, here's what I have in my App.config file:
<add name="[APPLICATIONNAME].My.MySettings.LocalDevServerConnectionString"
connectionString="Data Source=[YOURCOMPUTERNAME];Initial Catalog=[DBYOUWANTTOCONNECTOT];Integrated Security=True"
providerName="System.Data.SqlClient" />