Reputation: 19
I have built an application in C# . I intend to make a msi installer file using install shield . The application installs and runs fine on my PC when I try to install it somewhere else it gives me a bad error
"Object Reference not set to an instance of an object at run time ."
For the purpose of clarity I would like to explain the first form is a login form . The application runs on my native PC means it is fine running application. But I don't know why does it cause so much trouble.
The Connection String is :
<connectionStrings>
<add name="ConString" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=test; AttachDBFileName=D:\test.mdf; Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
For the purpose of ease I have not added any usernames and passwords yet.
I tried many times changing the destination of attached DBFILENAME
to |DataDirectory|test.mdf
...etc but on the client PC that didn't work either.
Does it mean that I have to install SSMS(SQL Server Management Studio)? That is the only thing I didn't install on the client PC.
Upvotes: 1
Views: 1584
Reputation: 4087
You can Try either of the following:
The SQL Server Database must be installed somewhere on your client's machine so that your Application can gain access to it only when you have attached (test.mdf)
along your Application.
Or, You can simply install your SQL Server only on Server machine and you don't have to install SQL Server along with your Application on each Client machine everytime.
Upvotes: 1
Reputation: 3993
If you want a single user database, you need to ensure that sql express is installed on the target machine. Otherwise you will need a server to point to.
AttachDBFilename is unique to SQL Express, it spins up a user instance of SQL Express attached to a specific DB Filename for single user mode. Database is simply the name of the database to use, it has no additional connotation. For any production server, you would most likely not be using AttachDBFilename. It is strictly useful for development and experimentation in single-user mode.
You had to change data source=.\SQLEXPRESS on the production server because it did not have a named instance of SQL Express running on it. The syntax of a server name is \. Note that a blank is equated to the default instance. In your case, the web server is running a default instance of SQL Server. The option to install a default instance is available in SQLEXPRESS as well, though you have to select it explicitly or else it installs as a named instance with the name SQLEXPRESS. You could have used (local) or localhost or . or instead of the IP on the server, so long as you don't specify an absent instance name.
Upvotes: 0