locked
sqlDataSource Class in C# and Connection String RRS feed

  • Question

  • User-867185030 posted

                  Hi everybody

                i want to add a connection to my database in my code C# , but the visual studio did'nt detect my data source

                                 

       SqlDataSource dss = new SqlDataSource();
       dss.ID = "sqlgl";
       dss.ConnectionString = ";data source=W2K8\SQLEXPRESS;initial catalog=YesRems;integrated security=True;";
       dss.SelectCommand = "SELECT 
    ,[PKey] FROM [AdmRole]";
    
                              

                                  it didn't detect the "\" caracter

    Thursday, August 23, 2012 10:38 AM

Answers

  • User281026190 posted

    Hi, friend

    In your ConnectionString there is Error Syntax. please remove ';' symbol that placed in First and End ConnectionString. Try to replace your ConnectionString to one of these ConnectionString Format. Hope get help.

    • "datasource=servername; initial catalog=databasename; integrated security=true"
    • "server=servername; database=databasename; integrated security=true"
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 2:52 PM
  • User3866881 posted

    but the visual studio did'nt detect my data source

    I suggest you trying to open Vs and then turn to "View"=>"Server Explorer" and the create a remote connection to the sepcific database and then copy the connection string.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 25, 2012 5:12 AM

All replies

  • User1191505944 posted

    Try this,

    dss.ConnectionString = "data source=W2K8\SQLEXPRESS;initial catalog=YesRems;integrated security=True;";

    Thursday, August 23, 2012 11:20 AM
  • User281026190 posted

    Hi, friend

    In your ConnectionString there is Error Syntax. please remove ';' symbol that placed in First and End ConnectionString. Try to replace your ConnectionString to one of these ConnectionString Format. Hope get help.

    • "datasource=servername; initial catalog=databasename; integrated security=true"
    • "server=servername; database=databasename; integrated security=true"
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 2:52 PM
  • User3866881 posted

    but the visual studio did'nt detect my data source

    I suggest you trying to open Vs and then turn to "View"=>"Server Explorer" and the create a remote connection to the sepcific database and then copy the connection string.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 25, 2012 5:12 AM