Click to See Complete Forum and Search --> : Error in SqlConnection


TheLastBurden
04-01-2006, 05:34 AM
Am using Sybase Adaptive Server anywhere 8.0 and get the following error when i try to connect to the database.

Error :

Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.

Line 28: objCmd = New SqlCommand(V_SQL,objConn)
Line 29: objConn.Open()
Line 30: objRS=objCmd.ExecuteReader(CommandBehavior.CloseConnection)


Dim v_str="Data Source=ASAProv.80;Initial Catalog=HelpDesk;User ID=dba;Password=sql;"
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim objRs As SqlDataReader
Dim V_SQL As String
objConn= New SqlConnection(v_str)

I have a feeling that I haven't configured my server properly.
Should I use any service under Administrative Tools/Services in any way?

sirpelidor
04-01-2006, 12:34 PM
Hi,
Are you importing Importing System.Data.SqlClient instead of System.Data.OleDb?

Sybase anywhere uses OleDB as a connector. Looks like you are calling SqlClient object instead of OleDbClient object.

TheLastBurden
04-02-2006, 12:32 AM
i tried using System.Data.OleDb ..Didn't work..so i tried another approach which seems to have worked for many....but i still get an error
Am posting the code where the problem might be...

<%@ Page Language="VB" Debug="true" aspcompat=true CompilerOptions='/R:"C:\Program Files\Microsoft.NET\Odbc.Net\Microsoft.data.odbc.dll"'%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.Data.Odbc" %>
' Reckon there's an Error in My Connection String ?
Dim strconn as String = "DRIVER={Sybase ASA 8};UID=da;PWD=sql;"
Dim conn as ODBCConnection = new ODBCConnection(strconn)
Dim strSQL as string = "SELECT * FROM TABLE_NAME"
Dim query as ODBCDataAdapter = New ODBCDataAdapter(strSQL, conn)
Dim objRS as Dataset = new DataSet()
query.fill(objRS)

' Error :

Exception Details: Microsoft.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Source Error:
Line 26: Dim query as ODBCDataAdapter = New ODBCDataAdapter(strSQL, conn)
Line 27: Dim objRS as Dataset = new DataSet()
Line 28: query.fill(objRS)

masoom
04-02-2006, 06:36 AM
All rite you need to click on serverexplorer delete the present connection and then click on new database connection,when the authenciation box pops up enter the userid & password you write in your connection string.that's all what you need to do.

TheLastBurden
04-03-2006, 01:13 AM
Dim objConn as New OleDbConnection("Provider=ASAProv;Data Source=helpdesk;User ID=dba; Password=sql;")
Dim objCmd as OleDbDataAdapter=New OleDbDataAdapter(V_SQL,objConn)
Dim objRS as DataSet=New DataSet()
objCmd.Fill(objRS)

This is whta i used and it works fine now.Thanx ..Anyway....

However am having a concatenation error ... tried replacing & with + and + with & , both give errors..can't seem to find the error .

TheLastBurden
04-03-2006, 01:34 AM
just in case..here's the code ...


V_SQL="INSERT INTO DBA.helpdesk_request_trn(id,id_employee_mst,id_problem_type_mst,Subject,Details,status,priority) "
V_SQL=V_SQL + "VALUES(26,"
V_SQL=V_SQL + v_emp_id + ","
V_SQL=V_SQL + v_prob_id + ","
V_SQL=V_SQL + v_subject + ","
V_SQL=V_SQL + v_Desc + ",'Not Started',"
V_SQL=V_SQL + v_priority + ")


v_emp_id,v_prob_id are the varaiables...when hardcoded there's no error...

sirpelidor
04-03-2006, 01:22 PM
What I normally do if I were you, is print the V_SQL string using response.write, and copy to enterprise manager and see what part of my sql string cause errors...

TheLastBurden
04-04-2006, 12:35 AM
i got it ..
i used '&' as we do in Classic ASP , it's necessary to have a space before and after the varaiable .

V_SQL="INSERT INTO DBA.helpdesk_request_trn(id,id_employee_mst,id_problem_type_mst,Subject,Details,status,priority) "
V_SQL=V_SQL & "VALUES(26,"
V_SQL=V_SQL & v_emp_id & ","
V_SQL=V_SQL & v_prob_id & ","
V_SQL=V_SQL & v_subject & ","
V_SQL=V_SQL & v_Desc & ",'Not Started',"
V_SQL=V_SQL & v_priority & ")

Thanx Anyway