Use ASP.Net insert command to apply on an ORACLE database table

0

Good day! I'm trying to insert just an entity to a single field in an ORACLE database table but I'm having this error in my Stack Trace:

**Stack Trace**: 

[OracleException (0x80131938): ORA-12154: TNS:could not resolve the connect identifier specified ] System.Data.OracleClient.OracleException.Check(OciErrorHandle errorHandle, Int32 rc) +338968 System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName) +879 System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions) +129 System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +40 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +548 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +69 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +470 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +118 System.Data.OracleClient.OracleConnection.Open() +43 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +378 System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +399 System.Web.UI.WebControls.SqlDataSource.Insert() +19 ASP.jtrap_import_aspx.InsertWeight(Object Source, EventArgs e) in E:\Documents\Visual Studio 2013\Projects\jTRAP_net v1\jTRAP_net\jTRAP_import.aspx:12 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628722 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Here is my data source:

<asp:Sqldatasource
ID="OracleServer1" Runat="server" 
ConnectionString="Data Source=OracleServer1;Persist Security Info=True;"
ProviderName="System.Data.OracleClient"
InsertCommand="INSERT INTO tbl_object(WEIGHT) VALUES(@Weigh)">
      <insertparameters>
        <asp:formparameter name="Weigh" formfield="TextBox1" />            
      </insertparameters>
</asp:Sqldatasource>

And here is my connection string located in my Web.config:

<connectionStrings>

 <add name="OracleConnectionString" 
  connectionString="Data Source=OracleServer1;Persist 
  Security Info=True;" 
  providerName="System.Data.OracleClient" 
/> 

Your help would be appreciated!

asp.net
oracle
asked on Stack Overflow Jun 20, 2015 by TDL • edited Jun 20, 2015 by Nagaraj S

1 Answer

0

I've made a better choice of doing it in the code behind as I'm more familiar w/ this method and made it work:

code behind:

    Dim strConnection As String = ConfigurationManager.ConnectionStrings("OracleConnectionString").ConnectionString
    Dim oracleConnection As New Oracle.DataAccess.Client.OracleConnection(strConnection)

    If oracleConnection.State = ConnectionState.Closed Then
        MsgBox("Opening oracle connection")
        oracleConnection.Open()
        MsgBox("Oracle connection successfully opened.")
    End If


    Dim strQuery As String = "INSERT INTO ......(so on)"
    Dim oracleCommand As New OracleCommand(strQuery, oracleConnection)

    MsgBox("Inserting values to the table")

    oracleCommand.ExecuteNonQuery()

    MsgBox("Successfully inserted values into the table")

And here's my connection string code in the web.config file

<connectionStrings>
 <add name="OracleConnectionString" 
  connectionString="Data Source=localhost;USER ID=username;PASSWORD=password" 
  providerName="Oracle.DataAccess.Client" 
/>  </connectionStrings>
answered on Stack Overflow Jun 21, 2015 by TDL

User contributions licensed under CC BY-SA 3.0