Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am facing one problem in setting connection string
In my one project during set up project i have set my connection string to

Dim constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\DB\NDA.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

where DB is folder name,
with the help of this i need not install database to client machine


but this connection string giving problem in App.config file and giving error on Application.StartupPath word
what should be reason and solution for that
Posted
Comments
OriginalGriff 7-May-11 7:02am    
What error is it giving?
Ankur\m/ 7-May-11 7:08am    
OP wrote:
it is giving error on Application.StartupPath word key word not found
Mayur Gujrathiii 7-May-11 7:06am    
it is giving error on Application.StartupPath word key word not found
NuttingCDEF 7-May-11 7:21am    
Compiler error or runtime error?
Mayur Gujrathiii 7-May-11 7:44am    
compile time error

The only reason I can think of for that is if you are trying to use it in a class or application which does not reference Windows.System.Forms. Is this a Web application, at all?
 
Share this answer
 
Comments
Mayur Gujrathiii 7-May-11 7:41am    
yes it is windows application
OriginalGriff 7-May-11 7:49am    
Does it change at all if you make the reference explicit?
Dim constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" + System.Windows.Forms.Application.StartupPath + "\DB\NDA.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

What happens if you take out the two fixed strings - just for testing - do you still get the error?
See http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.71).aspx[^] for valid key words.

This doesn't list User Instance - so might that be an issue?

If so, see also http://social.msdn.microsoft.com/Forums/en-US/sqlgetstarted/thread/45700f5c-59ba-41cd-ac59-46873f26845a/[^] which gives further info on User Instance and how to get it working.

Never tried it myself, but someone there thinks they found a solution.

Hope this helps.
 
Share this answer
 
You have "Dim constr As String " - that looks like VB not C# - if so, isn't the correct string concatenation operator "&" and not "+"?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900