SQL Server Express exception in desktop .NET application -


i have developed .net desktop application uses sql server 2005 sp3 express.

after installing sql server express runtime , application on windows 7 64 bit machine, following error after launching application:

system.data.sqlclient.sqlexception: failed generate user instance of sql server due failure in starting process user instance. connection closed.

the connection string have used in <application>.exe.config file :

<add name="cs" connectionstring="data source=.\sqlexpress;     attachdbfilename=|datadirectory|\appdata\mwaiwfmle1.mdf;     integrated security=true;     user instance=true"     providername="system.data.sqlclient" /> 

the mwaiwfmle1.mdf file located in folder called appdata in application install directory under program files - hence appdata in attachdbfilename path.

am missing here?

read very overview of user instances are.

in nutshell:

  • sql server allows have multiple instances of on single computer - default instance can accessed using machine name (or ip address) of host machine - other instances need specified instance name (like sqlexpress on machine)

  • for development purposes, can create user instance - each user gets own separate instance of sql server (works in express edition only) , database attached file name (path\sales_db.mdf) user instance. instance started on demand, runs , shut down when no longer needed

while works great development, it's not intended later on - not production use.

in production environment, want attach database files actual sql server instance should run on - typically using sql server management studio. when this, no longer refer database via file name, instead use database name given database when being attached server. in case, sql server handle details of operations - , sql server instance , running time (doesn't need started "on demand" time), , can use things permissions , logins control access database.

your connection string this:

<connectionstrings>     <add name="sales_dbentities"           connectionstring="server=.\sqlexpress;database=yourdatabasenamehere;integrated security=sspi;" /> </connectionstrings> 

when have attached database production (or testing) sql server instance, not need know files make database, , don't need specify files - sql server take care of that. refer database via database name.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -