Connection string problem

Last post 11-28-2007 5:53 AM by sunny_popali. 10 replies.

Sort Posts:

  • Connection string problem

    09-19-2005, 12:08 PM
    • Participant
      1,266 point Participant
    • mhariri
    • Member since 11-15-2004, 8:35 PM
    • Posts 502
    Hi,

    I am trying to use the conenction string in my web.config file in my C# application but somehow I can not get it to work. I posted a couple of messages before but still have not heard anythng back. I have

    String ConnectionString = "Provider=MSDAORA;Data Source=xxx;User ID=xxx; Password=xxx;";

    and I like to use the connection string defined in my web.config when I try the following

    String ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["xxx"].ConnectionString.ToString();

    I end up with an error eventhough xxx is defined in my web.config as a standard connectin string. Any ideas on what I am doing wrong?

    Here is what is in web.config

    <connectionStrings>

    <add name="xxx" connectionString="Data Source=xxx;Persist Security Info=True;User ID=xxx;Password=xxx" providerName="System.Data.OracleClient" />

    </connectionStrings>

  • Re: Connection string problem

    09-19-2005, 3:57 PM
    • Participant
      1,070 point Participant
    • irinelc
    • Member since 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • AspNetTeam

    Hi
    What does the error say? I couldn't repro the error you get. Here is my connection string in the web.config:

    <
    connectionStrings>
       <
    add name="ConnectionString" connectionString="Data Source=myoracleserver;Persist Security Info=True;User ID=myuser;Password=mypassword;Unicode=True" providerName="System.Data.OracleClient"/>
    </
    connectionStrings>

    Here is the call I make in the Page_Load (VB)
            
    Dim
    strConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

    and C#
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    Hope this helps
    Irinel

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Connection string problem

    09-20-2005, 8:21 AM
    • Participant
      1,266 point Participant
    • mhariri
    • Member since 11-15-2004, 8:35 PM
    • Posts 502
    Thank you it works! I am not sure what I was doing wrong but I could swear it was working with my old code and suddenly stopped working.

    Mo
  • Re: Connection string problem

    09-20-2005, 10:10 AM
    • Participant
      1,266 point Participant
    • mhariri
    • Member since 11-15-2004, 8:35 PM
    • Posts 502
    Hi,
    The problem is back. I am using the following

    String ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["XXX"].ConnectionString;
    OleDbConnection DBConnection = new OleDbConnection(ConnectionString );
    OleDbDataAdapter DBAdapter;
    DataSet ResultsDataSet = new DataSet();

    and  when I try to run the application I get the following

    An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.

    Source Error:

    Line 194:   
    Line 195:     
    Line 196:   OleDbConnection DBConnection = new OleDbConnection(ConnectionString );
    Line 197:   OleDbDataAdapter DBAdapter;
    


    Any Ideas?
  • Re: Connection string problem

    09-20-2005, 1:00 PM
    • Participant
      1,070 point Participant
    • irinelc
    • Member since 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • AspNetTeam
    This error usually occurs when using an OleDbConnection with a connection string that is not specific to the OleDb provider. There are two options:

    1. Keep OleDbConection DBConnection = .... and change the connection string format to
              
    ConnectionString ="Provider=SQLOLEDB;Data Source=myServer;Password=myPassword;User ID=myUser;Initial Catalog=pubs"

     2. Define a SqlClient connection and keep the connection string format you already have 
              ConnectionString ="Data Source=myServer;Password=myPassword;User ID=myUser;Initial Catalog=pubs"

    Hope this helps
    Irinel

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Connection string problem

    09-29-2005, 3:04 PM
    • Participant
      1,266 point Participant
    • mhariri
    • Member since 11-15-2004, 8:35 PM
    • Posts 502
    I am back! I still haven't found a solution for this problem. I am using OleDB because my datasource is Oracle. and my web.config has the following:

    <add name="xxx" connectionString="Data Source=xxx.com;Persist Security Info=True;User ID=xxx;Password=xxx" providerName="System.Data.OracleClient" />

    And I am not sure sure how to apply your recommendation. I have

    String ConnectionString =System.Configuration.ConfigurationManager.ConnectionStrings["xxx"].ConnectionString;

    and I am getting the folowing error:

     

    Server Error in '/' Application.

    An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.

    Source Error:

    Line 194:   
    
    Line 196:   OleDbConnection DBConnection = new OleDbConnection(ConnectionString );
    Line 197:   OleDbDataAdapter DBAdapter;
    

    Are you saying to create a new connection string in web.config? I tried changing the provider in web.config to System.Data.OleDb but got the same error.

    Thanks,
    Mo

  • Re: Connection string problem

    10-31-2005, 1:56 PM
    • Participant
      1,070 point Participant
    • irinelc
    • Member since 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • AspNetTeam
    Hi

    Ohh, I see now. We are talking about an Oracle server.... Sorry for the confusion! If the server is Oracle you can use the Oracle provider or the OleDb provider.

    Here is the the connection in the web.config for the Oracle server with the Oracle provider.
    <connectionStrings>
          <
    add name="ConnectionString" connectionString="Data Source=MyOracleServerNameHere;User ID=MyUserNameHere;Password=MyPasswordHere;Unicode=True" providerName="System.Data.OracleClient"/>
    </
    connectionStrings>

    Here is the the connection in the web.config for the Oracle server with the OleDb provider.
    <connectionStrings>
        
    <add name="ConnectionString2" connectionString="Provider=MSDAORA;Data Source=MyOracleServerNameHere;Password=MyPasswordHere;User ID=MyUserNameHere" providerName="System.Data.OleDb" />
    </connectionStrings>

    Make sure that in the code you define the Oracle connection if you are using the Oracle provider or an Oledb connection if you are using the OleDb provider

    Hope this helps
    Irinel
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Connection string problem

    01-16-2006, 2:25 AM
    • Member
      25 point Member
    • elektra
    • Member since 01-13-2006, 6:23 AM
    • Posts 5

    irinelc,

    I had the same problem and when I try to follow what u suggested, I get this error

    "Type or Namespace ConfigurationManager does not exist in System.Configuration.."

    Am I missing to include an assembly ref? Please guide me with a way out.

    My datasource is oracle, I'm using an OleDbprovider for connection.

    TIA,

    Elektra

  • Re: Connection string problem

    01-16-2006, 1:02 PM
    • Participant
      1,070 point Participant
    • irinelc
    • Member since 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • AspNetTeam

    Hi

    What Framework version are you on?

    Irinel

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Connection string problem

    01-17-2006, 1:47 AM
    • Member
      25 point Member
    • elektra
    • Member since 01-13-2006, 6:23 AM
    • Posts 5

    i am using .net v.1.1.4322

    also, i see a problem with the provider i use for connection. With oledbdrivers installed on my machine, can u help me why i get the error as:

    TNS couldn't resolve service name.

    this is my connection string:

    using System.Data.OleDb;
    ...
    OleDbConnection  oracleConn = new OleDbConnection();
    oracleConn.ConnectionString = "Provider=\"OraOLEDB.Oracle.1\";
                                  User ID=scott;Password=tiger;
                                  Data Source=yourSource;
                                  Extended Properties="";
                                  Persist Security Info=False";
    oracleConn.Open();

  • Re: Connection string problem

    11-28-2007, 5:53 AM
    • Member
      37 point Member
    • sunny_popali
    • Member since 06-19-2007, 1:42 PM
    • Posts 48

     Thank you. This has solved my access connectivity problem.

     

    Regards,

    -Sunny. 

Page 1 of 1 (11 items)