This is driving me nuts! I read the Faq (amazing amount of info there) and followed the suggestions but to no avail.
Here is my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim connectionString As String = "Data Source= JCS\SQLEXPRESS;Initial Catalog=FMC_ACCESS;Integrated Security=True"
Using Connection As New SqlConnection(connectionString)
Connection.Open()
Dim sqlCMD As System.Data.IDbCommand = Connection.CreateCommand()
sqlCMD.CommandText = "SELECT ROUND(CMPatientDataFile.Result_Numeric,2),CMPatientDataFile.Run_Date FROM CMPatientDataFile WHERE CMPatientDataFile.Pat_ID = '10364.0' AND CMPatientDataFile.Test_Name = 'GLUC' ORDER BY CMPatientDataFile.Run_Date"
Dim mytable As DBTable = New DBTable(sqlCMD.ExecuteReader())
Dim result() As Double = mytable.getCol(0)
Dim RunDate() As Date = mytable.getColAsDateTime(1)
(Rest isn't important)
End Using
End Sub
This works quite nicely and makes a very pretty chart based on the values retrieved from the SQL DB.
But I also have an Oracle 10g Express DB and need to run the same code with the exception of the connect string and the query. I can't get it to connect. It shows error 40, can't find the database.
Now:
1. I CAN connect to the Oracle DB and retrieve data with a query if I drag the "SQLDataSource" to the design page and configure it properly. I dumped the data into a gridview. It worked great. (Not using the code on the aspx.vb page)
2. I can connect and run a query using a program called 'Query Reporter'.
3. I downloaded the program in the Faq to find the connection string. Using OLE DB Provider for Oracle it connected and gave this as a connect string: Provider=MSDAORA.1;Password=hr;User ID=hr;Data Source=xe;Persist Security Info=True
Using the Provider= part causes an error (not supported) so I tried it without that part and received an error. Below is the error report.
ANY help would be so greatly appreciated!
System.Data.SqlClient.SqlException was unhandled by user code
Class=20
ErrorCode=-2146232060
LineNumber=0
Message="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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
Number=2
Server=""
Source=".Net SqlClient Data Provider"
State=0
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at _Default.Page_Load(Object sender, EventArgs e) in Z:\Dev_Websites\SQLConnect_label\Default.aspx.vb:line 11
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Here is my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim connectionString As String = "Data Source= JCS\SQLEXPRESS;Initial Catalog=FMC_ACCESS;Integrated Security=True"
Using Connection As New SqlConnection(connectionString)
Connection.Open()
Dim sqlCMD As System.Data.IDbCommand = Connection.CreateCommand()
sqlCMD.CommandText = "SELECT ROUND(CMPatientDataFile.Result_Numeric,2),CMPatientDataFile.Run_Date FROM CMPatientDataFile WHERE CMPatientDataFile.Pat_ID = '10364.0' AND CMPatientDataFile.Test_Name = 'GLUC' ORDER BY CMPatientDataFile.Run_Date"
Dim mytable As DBTable = New DBTable(sqlCMD.ExecuteReader())
Dim result() As Double = mytable.getCol(0)
Dim RunDate() As Date = mytable.getColAsDateTime(1)
(Rest isn't important)
End Using
End Sub
This works quite nicely and makes a very pretty chart based on the values retrieved from the SQL DB.
But I also have an Oracle 10g Express DB and need to run the same code with the exception of the connect string and the query. I can't get it to connect. It shows error 40, can't find the database.
Now:
1. I CAN connect to the Oracle DB and retrieve data with a query if I drag the "SQLDataSource" to the design page and configure it properly. I dumped the data into a gridview. It worked great. (Not using the code on the aspx.vb page)
2. I can connect and run a query using a program called 'Query Reporter'.
3. I downloaded the program in the Faq to find the connection string. Using OLE DB Provider for Oracle it connected and gave this as a connect string: Provider=MSDAORA.1;Password=hr;User ID=hr;Data Source=xe;Persist Security Info=True
Using the Provider= part causes an error (not supported) so I tried it without that part and received an error. Below is the error report.
ANY help would be so greatly appreciated!
System.Data.SqlClient.SqlException was unhandled by user code
Class=20
ErrorCode=-2146232060
LineNumber=0
Message="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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
Number=2
Server=""
Source=".Net SqlClient Data Provider"
State=0
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at _Default.Page_Load(Object sender, EventArgs e) in Z:\Dev_Websites\SQLConnect_label\Default.aspx.vb:line 11
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)