sql - Using Oledb connection string for Localhost c# -


when use oledb c# connection noticed lot connection using file. how connect localhost using oledb? created database , tables using microsoft sql server management connect sql express , using window authentication

when using function don't know how should convert connect localhost

//want connstring connect localhost instead of file public static string connstring = @"provider=microsoft.jet.oledb.4.0;data source=" + path + "\\database\\errdb.mdb"; public static oledbconnection connection;  public myfunction() {     string sqlstring = "select name,contact,accesslevel,crudential_id errors crudential_id =@id";     connection = new oledbconnection(connstring);     oledbcommand command = new oledbcommand(sqlstring, connection);      //open connection     connection.open();      command.parameters.add("@id", oledbtype.varchar);     command.parameters["@id"].value = "test";      //read database     oledbdatareader reader = command.executereader();     if(reader.hasrows)     {        .....     }     connection.close(); } 

connectionstrings.com - true name - indispensable when need construct connection strings. specific case, this relevant section.

based on that, connection string should this:

provider=sqlncli11;server=.\sqlexpress;database=somedatabase;trusted_connection=yes; 

to break down:

  • sqlncli11 sql native client oledb provider. can see available providers in sql management studio, under server objects > linked servers > providers.
  • .\sqlexpress servername , instance. . shorthand localhost (you can use localhost if prefer), , sqlexpress default instance name sql express installs under.
  • somedatabase - whatever database name is.
  • trusted_connection=yes - use windows authentication. sometime see integrated security=sspi. 1 , same.

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -