1

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.

4
  • Well, you are looking for a local database. If you are wanting to use a database, you will need to either have a local one or access to a remote one. If you are accessing a remote DB then you will need to set up a connection string to use for initializing your database connection. Commented May 18, 2016 at 18:08
  • (LocalDB)\v11.0; is from your local PC. How could the client access the database from that? You would need to configure the connectionString to match the server. You receive the error message "Object Reference is not set" is because whatever the client is trying to access returns null. I don't know what it is because I don't have much information. Commented May 18, 2016 at 18:08
  • You need to post the actual code that throws that exception. Commented May 18, 2016 at 18:26
  • By client machine I mean a stand alone offline PC that has SQL Server LocalDb Installed on it. Secondly it looks like a connection string problem to me when I use AttachDBFileName the application gives the same error on my developer PC. How to change this connection string please? Commented May 18, 2016 at 22:05

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't want to use a server machine I want the Client to take away his PC and do whatever he wants. Its just that I didn't mention that I am using a Server .
so it's better you follow the above step. Just install the Express Edition on the Clients' Machine...that'll do.
0

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.

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f21c0728-935d-492a-baaf-ff2704e3683b/attachdbfilename-option-in-connection-string?forum=sqldataaccess

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.