Kill Oracle sessions using vb.net [closed] - vb.net

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
How do you get a vb.net program to send a session kill command to Oracle? I can do it in sqlplusw by just typing:
alter system kill session '45,30665';
In vb.net, I'm trying to do this with an oracle.dataAccess object:
oraConn As New OracleConnection("Data Source=db1;User ID=usr;Password=pw")
oraConn.Open()
Dim cmd As New OracleCommand
cmd.Connection = oraConn
cmd.CommandType = CommandType.Text
cmd.CommandText = "alter system kill session '45,30665';"
cmd.ExecuteNonQuery()
cmd.Dispose()
When it gets to the ExecuteNonQuery line, it throws an exception "ORA-00911: invalid character". I think it's expecting an SQL statement. I'm using VB Express 2008.

You don't want semicolons in statements that you're sending from a client. Get rid of the semicolon at the end of the alter system
cmd.CommandText = "alter system kill session '45,30665'"

Related

Syntax error (missing operator) in query expression ‘[Type]=5 And Left([Name],1)<>"~" OORDER BY [Name]’ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have to create a list box control that contains all of the queries except for the system queries. Recall that system query names begin with the ~ character.
When I try to write SQL code in the row source (in the property sheet) for my frmQueries form I keep getting an error saying:
Syntax error (missing operator) in query expression:'[Type]=5 And Left([Name],1)<>"~" OORDER BY [Name]'
The code I entered is:
SELECT [Name] FROM MYSysObjects
WHERE [Type]=5 And Left([Name],1)<>"~"
OORDER BY [Name];
I am not sure why I am getting this error or how I can fix it.
OORDER should be ORDER, MYSysObjects should (presumably) be MSysObjects, and you can also replace Left([Name],1)<>"~" with [Name] not like "~*" (assuming MS Access instead of SQL Server).

Fetching VB Variables to insert with SQL Query [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Hello everybody hope you are well.
I have a place on a project im working on that im struggling to get past. I'm basically gathering meta data of a song and assigning them to variables in VB.
I'm next trying to save this data to a SQL database with tables i have created in visual studio and im having trouble doing this. The problem lies within trying to link the VB variables into a SQL query. Any Ideas?
To link VB variables to an SQL query, you need to add parameters that store the variables and then use those parameters in your SQL command:
Using parameters
MyCommand = New SqlCommand("SELECT Height, Weight, DoB, Gender, FROM `User` WHERE Username = #Username", DatabaseConnection)
MyCommand.Parameters.AddWithValue("#Username", Username)
UPDATE: How to connect to database
'Leads to the database
Public Filename As String = $"{AppDomain.CurrentDomain.BaseDirectory}YourDatabase.accdb"
'The connection string is set
Public ConStr As String = $"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA Source = {Filename}"
'The connection to the database is defined
Public DatabaseConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConStr)

Syntax not valid on word 'ON' in SQL join statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to run an SQL SELECT statement which is running correctly in SQL Server Management Studio, but I keep receiving the error while trying to run the below code in Visual Basic/Studio:
In correct syntax near the word 'ON'
Code:
com = New SqlCommand("SELECT Member_Details.mMember_ID AS 'Unique ID', Member_Details.mFirst_Name + Member_Details.mLast_Name AS 'Name', CONVERT(varchar(10),Member_Details.mDoB,103) AS 'Date of Birth', Member_Details.mGender AS 'Gender', Rep_Group.rRep_Group_Name AS 'Rep Group'" & _
"FROM Member_Details" & _
"Join(Rep_Group) ON Member_Details.mRep_Group=Rep_Group.rRep_Group_ID", con)
The error message:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'ON'.
The SQL Statement does work without the Join statement, so I think I'm just formatting it wrong in Visual Studio.
Replace Join(Rep_Group) with Join Rep_Group in your code. JOIN is not a function :)

SQL query returning Too Few Parameters [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have an access database that I am attempting to reference a SQL query
Set dba = CurrentDb
SQL = "SELECT * FROM tbl_NewHireStep WHERE Location = '" & Site & "' AND E-Verified = TRUE "
Set rst = dba.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
Keeps giving me a Too few parameters error. In SQL it works great. What am I doing wrong?
The hyphen, -, is an Access reserved symbol. If you want to use it in a field or table name, then you must always put that field or table name inside square brackets when you reference it. For example,
SQL = " SELECT * FROM tbl_NewHireStep " & _
" WHERE Location = '" & Site & "' AND [E-Verified] = TRUE "
It's far better to avoid using reserved words and symbols in the first place. Several years ago, Allen Browne compiled a list of Problem names and reserved words in Access. I'm not sure how current the list is, but it is a great reference when creating new database schemas.

Getting error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
this is my code
sqlcommand=new sqlcommand("inset into table values('"+home.name'"+,'"+home.DOJ'")",con);
You're using the local default string conversion from DateTime (I assume) to string, and then hoping that's valid for SQL.
Additionally, your code has a SQL injection attack vulnerability.
Both of these can be fixed - and your code readability - can be improved using parameterized SQL:
using (var command = new SqlCommand(
"INSERT INTO Foo (Name, DOJ) Values (#Name, #DOJ)", connection))
{
command.Parameters.Add("#Name", SqlDbType.VarChar).Value = home.name;
command.Parameters.Add("#DOJ", SqlDbType.DateTime).Value = home.DOJ;
...
}
(Adjust the types accordingly, e.g. using SqlDbType.NVarChar and SqlDbType.DateTime2.)
Never put values directly into SQL like you were doing. Using parameterized SQL is a win all round.