Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I don't know why I am getting this error when I deploy my web on server. Is it because the problem with my connection string? Please help me. Thank you!!!

Web.config
<add name="Database1" connectionstring="Data Source='170.21.191.85';Initial Catalog='Database1';User ID='sa';Password='123'" />



Login.aspx.vb
VB
Dim connection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Database1").ConnectionString()
    Dim mycon As New SqlConnection(connection)
Posted

Correct connectionstring to connectionString
<add name="Database1" connectionstring="Data Source='170.21.191.85';Initial Catalog='Database1';User ID='sa';Password='123'" />
 
Share this answer
 
Comments
lowpw 25-Feb-11 4:16am    
i still have the error: Object reference not set to an instance of an object
Check your string is in the right place in web.config:

XML
<configuration>
  <connectionStrings>
    <add name=.../>
  </connectionStrings>
...


[edit]Spurious <ConfigSections> removed - I missed the closing tag :-O - OriginalGriff[/edit]

I missed this the first time round: Take the "()" off your Login.aspx.vb:

VB
Dim connection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Database1").ConnectionString()
    Dim mycon As New SqlConnection(connection)

Becomes:
VB
Dim connection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Database1").ConnectionString
Dim mycon As New SqlConnection(connection)
 
Share this answer
 
v3
Comments
lowpw 25-Feb-11 4:10am    
i have error putting it under <configsections>
OriginalGriff 25-Feb-11 4:12am    
Sorry? Please try to say that again - I do not understand you.
lowpw 25-Feb-11 4:13am    
i have error putting the connectionString under configSections
OriginalGriff 25-Feb-11 4:25am    
I missed the closing tag - sorry: Answer updated.
Espen Harlinn 25-Feb-11 10:52am    
Seems OP didn't appriciate your efforts, my 5

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