how to write connection string for connect SQL database

Posted by Gow.Net under ASP.NET on 4/25/2012 | Points: 10 | Views : 2829 | Status : [Member] | Replies : 2
how to write connection string for connect SQL database in real time asp.net application

gowthaman8870226416


Responses

Posted by: Dotnetrajanikanth on: 4/25/2012 [Member] Starter | Points: 25

Up
0
Down
in web.config
<connectionStrings>

<add name="Conn" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\New Folder\WebApp\App_Data\Database.mdf;Integrated Security=True;User Instance=True"></add>
</connectionStrings>


in Code Behind

'Calling a function for connection
Dim connect As SqlConnection = ConnectToDatabase()


Connect To Database Function

'Getting the connection string
        Dim connectString As String = ConfigurationManager.ConnectionStrings("Conn").ConnectionString


'Creating connection object
Dim connect As SqlConnection = New SqlConnection(connectString)
Return connect



____________
www.flickr.com/photos/psdesigner/

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savariya on: 4/25/2012 [Member] Starter | Points: 25

Up
0
Down
you can also write this connection string in your web.config file

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response