How to specify "Service Name" in Oracle ODBC connection string - vba

I have an Excel macro that has an Oracle database connection. When I call the macro, it fills out user name and password but not service name. User has to enter service name manually every time.
How can I specify it in the connection string?
Connection string:
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;DB=" & inputHost & ";" & _
"DefaultIsolationLevel=READUNCOMMITTED"
Excel prompt:

Found it. It's DBQ
New connection string:
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"DBQ=" & inputHost & ";UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;DB=" & inputHost & ";" & _
"DefaultIsolationLevel=READUNCOMMITTED"

It depends on your driver, check this out
But without a config file, you have to specify the options in the connection string.
Give this a try,
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"SERVICE_NAME=" & inputHost & ";UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;" & _
"DefaultIsolationLevel=READUNCOMMITTED"
Also, make sure inputHost should be used in both cases where it is currently. One should be an instance of a server with the other being the database within it.

Related

No value given for one or more required parameters error on one machine but not another

I have VBA code working in Excel on my machine but it is giving the above error on someone else's machine. What would be causing it to work for me but not for someone else?
'---Connecting to the Data Source---
Set cn = CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & wb.Path & "\" & wb.Name & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
.Open
End With
'---Run the SQL SELECT Query---
sql = "SELECT " & _
"sum([" & cash_projections.Name & "$].[Projected Ending Balance]), " & _
"[" & cash_projections.Name & "$].[Account Name (Balance)], " & _
"[" & cash_projections.Name & "$].[Projected Date] " & _
"FROM " & _
"[" & cash_projections.Name & "$] " & _
"WHERE " & _
"[" & cash_projections.Name & "$].[Projected Ending Balance] > 100 " & _
"GROUP BY " & _
"[" & cash_projections.Name & "$].[Account Name (Balance)], " & _
"[" & cash_projections.Name & "$].[Projected Date] " & _
"ORDER BY " & _
"[" & cash_projections.Name & "$].[Account Name (Balance)], " & _
"[" & cash_projections.Name & "$].[Projected Date] "
Set rs = cn.Execute(sql)
The error shows up on the last line of this code. Again, it works just fine for me, but gives the error on another machine.
Please note that I am using the exact same workbook as is being used on the other computer. Here are the column headings
The line that is causing the error is the one that is executing your query. Because the code does not fail when you open the connection, it means it is finding the workbook you are querying just fine. My guess is that the workbook it finds has a different structure on the two machines. Because it says a parameter is missing a value, it means that something that is defined on your machine is missing on the other, it could be a table name or a column name. Basically, when you use that name on your machine it finds it and moves on. On the other machine, it can't find it so it assumes it must be parameter.

ms access 2007 update error run time error 3464, data type mismatch in criteria expression

i cannot update the data, it says that data type mismatch in criteria experession
CurrentDb.Execute "UPDATE PC_Details " & _
" SET Serial_No=" & Me.txtNo & _
", PC_Brand='" & Me.txtBrand & "'" & _
", PC_Model='" & Me.txtModel & "'" & _
", Status='" & Me.txtStatus & "'" & _
", Description='" & Me.txtDesc & "'" & _
", Staff_ID='" & Me.txtID & "'" & _
" WHERE Serial_No=" & Me.txtNo.Tag
Do this to debug:
Dim SQL As String
SQL = "UPDATE PC_Details " & _
" SET Serial_No=" & Me.txtNo & _
", PC_Brand='" & Me.txtBrand & "'" & _
", PC_Model='" & Me.txtModel & "'" & _
", Status='" & Me.txtStatus & "'" & _
", Description='" & Me.txtDesc & "'" & _
", Staff_ID='" & Me.txtID & "'" & _
" WHERE Serial_No=" & Me.txtNo.Tag
Debug.Print SQL
CurrentDb.Execute SQL
Then study the resulting SQL and post it here.
If all values are present, one or more is text but is handled as number or vice versa.

VB6 - Creating a Connection String based on text input

Ok I have a connection String - But I want to write an app where the user can enter their own values from a text box and that will be used in the connection
ConnectionObj.Open _
"Provider = sqloledb;" & _
"Data Source=" & Text1.Text; & _
"Initial Catalog=" & text2.text; & _
"User ID= text3.text ;" & _
"Password= text5.text ;"
Here's what I've tried
But that didn't work - any help would be greate appreciated
Since I figured it out I thought I'd post it : if someone would need this in the future :)
ConnectionObj.Open _
("Provider = sqloledb;" & _
"Data Source=" & Text1.Text & _
";Initial Catalog=" & Text2.Text & _
";User ID=" & Text3.Text & _
";Password=" & Text4.Text & ";")
Just to make things absolutely clear the "&" is a concatenation operator "&_" denotes a continued (Long) line
Best Task'

I'm trying to UPDATE some fields in my table in Access VBA

I need some help with this, sorry, I am new in VBA and I am trying to run a update query which should obtain a value from a variable and update an already existing table. This is done using VBA. On executing no error message is shown but the table isn't updated with the new value. The code is as follows:
Query = "UPDATE Results " & _
"SET fk_Report='" & Report & "'" & _
",fk_Name='" & Namevar & "'" & _
",fk_Age='" & Agevar & "'" & _
",fk_Sex='" & Sexvar & "'" & _
"WHERE [Count]='" & Countvar & "'" & _
",[Positives]='" & Posvar & "'" & _
",[Negatives]='" & Negvar & "'" & _
",[Unknow]='" & Unkvar & "';"
CurrentDb.Execute (Query)
If somebody can help...
You don't need the commas in the where clause
Query = "UPDATE Results " & _
"SET fk_Report='" & Report & "'" & _
",fk_Name='" & Namevar & "'" & _
",fk_Age='" & Agevar & "'" & _
",fk_Sex='" & Sexvar & "'" & _
"WHERE [Count]='" & Countvar & "' " & _
"AND [Positives]='" & Posvar & "' " & _
"AND [Negatives]='" & Negvar & "' " & _
"AND [Unknow]='" & Unkvar & "';"
CurrentDb.Execute (Query)
use AND instead of , (comma) after WHERE clause

vbscript that enters SQL and prints selected values to .txt file

I'm trying to connect to a SQL server(localhost) and extract the following:
SELECT INVOICENO, SUPPLIERID, AMOUNT, DOCID
FROM ES_TRANS_HEADER
WHERE READYTOINVOICE = 1
I then need to get this information into a .txt file, seperated by commas
This is what I got so far:
function accounting()
Dim myStream, connection, myCommand, recValue
Set myStream = CreateObject("ADODB.Stream")
Set connection = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command")
connection.Open "Provider=SQLNCLI10;" & _
"Data Source=localhost;" & _
"Integrated Security=SSPI;" & _
"Initial Catalog=SQLDatabase;" & _
"User ID=;Password="
myCommand.ActiveConnection=connection
myCommand.CommandText="SELECT INVOICENO,SUPPLIERID, AMOUNT, DOCID FROM ES_TRANS_HEADER WHERE READYTOINVOICE = 1"
SET recValue = myCommand.Execute()
If Not recValue.EOF then
MsgBox "INVOICENO = " & recValue(0) & vbcrlf & "SUPPLIERID=" & recValue(1) _
& "AMOUNT=" & recValue(2) & "DOCID=" & recValue(3)
End If
While Not recValue.EOF
INVOICENO = recValue(0)
SUPPLIERID = recValue(1)
AMOUNT = recValue(2)
DOCCID = recValue(3)
recValue.MoveNext
Wend
end function
Am I on the right track here, and if so what should I try to do next?
Thanks in advance
MsgBox didn't have any parentheses missing. Remove them (and read Eric Lippert's most awesome blog post on parentheses in VBScript). What's missing in that line is a line continuation character (_) at the end of the line. In VBScript you cannot wrap lines without that. Change this:
MsgBox ("INVOICENO = " & recValue(0) & vbcrlf & "SUPPLIERID=" & recValue(1)
& "AMOUNT=" & recValue(2) & "DOCID=" & recValue(3))
into this:
MsgBox "INVOICENO = " & recValue(0) & vbcrlf & "SUPPLIERID=" & recValue(1) _
& "AMOUNT=" & recValue(2) & "DOCID=" & recValue(3)
or put the whole statement in a single line:
MsgBox "INVOICENO = " & recValue(0) & vbcrlf & "SUPPLIERID=" & recValue(1) & "AMOUNT=" & recValue(2) & "DOCID=" & recValue(3)
As for the database connection, your connection string seems odd. According to the information provided here that connection string is for connections to a mirrored database. Try this instead:
db = "..." 'specify database name here
connection.Open "Provider=SQLNCLI10;" _
& "Server=localhost;" _
& "Database=" & db & ";" _
& "Trusted_Connection=yes;"
If that doesn't help: check the value of the connection's State property:
WScript.Echo connection.State
Also, update your question with any error you're getting (error number, error message and line number).