locked
Which connection string should I use if I use SqlConnection? RRS feed

  • Question

  • https://www.connectionstrings.com/sybase-adaptive/

    It is Adaptive Server Enterprise, so I guess I can only go with Sybase ASE OLE DB Provider or Adaptive Server Enterprise ODBC driver, if I am going to use SqlConnection con = new SqlConnection ("Connection String"), then which one should I use? Or it does not matter?

    Thanks.

    Edit: How should I know if my workplace computer/database comes with OLE DB providers? For ODBC, I can find the database under Control Panel > ODBC Data Source Administrator

    2nd Edit: If I try OLE DB connection string, then it returns "Keyword not supported: Provider"; if I try ODBC connection string, it returns "Keyword not support: Driver".

    • Edited by VA_er Friday, March 29, 2019 3:55 AM
    Friday, March 29, 2019 3:09 AM

All replies

  • SqlConnection class is meant for connection to Microsoft SQL Server database engine. To connect to Sybase ASE you should use either OdbcConnection or OleDbConnection class.

    But probably the best option is to use ADO.NET provider created for Sybase ASE. You can see link to information about it in the upper part of the page you have references with title "ASE ADO.NET Data Provider".

    • Proposed as answer by CoolDadTx Friday, March 29, 2019 1:52 PM
    Friday, March 29, 2019 5:41 AM
  • Hi

    Thank you for posting here.

    For your question, you want to know which connection string should you use if you use SqlConnection.

    Based on my search, Sqlconnection only Provides data access for Microsoft SQL Server.

    If you want to use Oledb or Odbc, you could refer to the following link.

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax

    Best regards,

    Jack

     


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 29, 2019 8:39 AM
  • https://www.encodedna.com/2013/01/asp.net-import-from-excel.htm

    Thanks. I mainly try to rewrite majority of  C# code in the above link. Let us say, I will go with ODBC connection string, then how can I convert below syntax into ODBC related syntax, in order to avoid such kind of error message. I am on statistical field, do not really know much about IT. Please review below conversion and let me know which are wrong.

    Thanks much!

    SqlBulkCopy --->  ??? (No such syntax OdbcBulkCopy)

    OleDbConnection myExcelConn  --- >  OdbcConnection myExcelConn

    OleDbCommand  ----> OdbcCommand

    OleDbDataReader  ---> OdbcDataReader

    using (SqlConnection con = new SqlConnection(sCon))  ---> using (OdbcConnection con = new OdbcConnection(sCon))

    Edit: I try to write Odbc everywhere I can, however, it seems there is some problem with below code syntax (see screenshot). If I don't have anything equivalent to SqlBulkCopy, how to write this portion of code(SqlBulkCopy, WriteToServer, etc)? I tried OleDbConnection too, same error message. It seems SqlBulkCopy does not apply to OdbcConnection/OleDbConnection. I am importing records about update or insert, depends on the system to decide if the record already exists.





    2nd Edit: I just found the link, but not sure how to convert write it in C#, no sample code available. I think the table does not have index, but what does trigger mean? http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20020_1251/html/databases/X18500.htm
    • Edited by VA_er Friday, March 29, 2019 1:03 PM
    Friday, March 29, 2019 11:44 AM
  • Thanks. Based on the response, I have edited the thread with further questions.
    Friday, March 29, 2019 11:55 AM
  • Hi

    It seems that your problem has been solved. If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 1, 2019 1:24 AM
  • Not yet, have not figured out ODBC connection Sybase bulk copy 

    A lot of my threads are for learning purpose, so I am not very dedicated to look for the answer. Just spend some spare time(to play around code) when I am free.

    Monday, April 1, 2019 1:36 AM
  • Hi

    Thanks for the feedback.

    Based on my search, the following link is similar to your problem.

    https://stackoverflow.com/questions/46529916/odbc-bulk-copy-c-sharp

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 1, 2019 2:37 AM
  • Thank you. I have actually found the same link before, but I don't feel like that is exactly I am looking for:

    1. I am not sure if it is so-called bulk copy.
    2. I will deal with xlsx file
    3. It indicates "MSDASQL", not Sybase.
    4. I don't think Insert is enough for me, I need Update the record if the record already exists.

    Thanks.

    Monday, April 1, 2019 11:42 AM
  • SqlConnection class is meant for connection to Microsoft SQL Server database engine. To connect to Sybase ASE you should use either OdbcConnection or OleDbConnection class.

    But probably the best option is to use ADO.NET provider created for Sybase ASE. You can see link to information about it in the upper part of the page you have references with title "ASE ADO.NET Data Provider".

    If I go with ADO.NET, which connection class should I use ? I am referring to something like: OdbcConnection or OleDbConnection.

    Thanks.

    https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-code-examples

    Thursday, April 11, 2019 2:14 AM