c# - SQL database connection failure in another computer through |DataDirectory| -
i have database , server application , works fine while i'm running on computer.
string connectionstring = @"data source=(localdb)\v11.0;attachdbfilename='|datadirectory|\fabrica.mdf';integrated security=true;connect timeout=30";
the problem is: have run application in computer , database must there well, when server application tries access database returns nothing. problem authentication? file path?
@edit: here's how i'm accessing tables:
sqlconnection con = new sqlconnection(connectionstring); sqlcommand cmd = new sqlcommand(); cmd.connection = con; cmd.commandtype = commandtype.text; cmd.commandtext = string.format("select * {0}", table); string name; sqldatareader reader; try { con.open(); reader = cmd.executereader(); while (reader.read()) { name = reader["name"].tostring(); } con.close(); } catch (exception e) { messagebox.show(e.tostring()); }
@edit: don't know if helps have sql server localdb , sql server express installed in other computer.
both authorization , filepath important.
localdb installed in computer , localdb, sql sever express installed in computer b(server) ?
localdb name 'local' means. means if want move computer, have re-localize localdb computer b.
manual way complicated have detach localdb localdb server in computer a(alter database immediate rollback has done in advance), , copy localdb file computer b , attach localdb file localdb server in computer b. , attachdbfilepath should indicate right path. |datadirectory| data directory of server application , it's not execution directory of server application. , importantly, detaching , attaching process needed because of ownership of localdb.
rather above complicated manual way, recommend automatic way add localdb .mdf file project of server application , make sure property 'content' , 'copy if newer' or 'copy always'. utilize automatically provided connectionstring change part |datadirectory|. if deploy server application then, localdb deployed data directory of server application , ownership of localdb automatically changed computer b.
i'm not sure how made application working fine in computer |datadirectory| , want advise understanding nature of localdb , meaning of |datadirectory| , connectionstring.
as per difficult experience, , private opinion if use |datadirectory|, can read(select) not able insert(modify) data. means need set(insert) data before add localdb project use |datadirectory|.
as reference, case set(inserted) fixed big data localdb , add project before deploy , coded application create new localdb after deployment insert(modify) function.
also, please refer answer else.
not inserting data database , not getting error
Comments
Post a Comment