Monday, March 19, 2012

Help about SQL server

Hi ,I am new learner to SQL server. We can either add the sqldatasource by add item option or use the external sql server.Can anybody tell me is it possible to use both of these ?if yes then what about the connection string? how can we connect to the database by connection string in web.config or which is generated through the sqldatasource?

Please help me......Your help is greatful to me.

Hi

SQLDatasource is typically accessed from the tools menu and when it is drag and dropped to the design view, it starts a wizard that would first prompt you to connect to a local or remot server. After giving necessary credintials it would connect to the SQLServer and then prompt you to provide a connection string. this connection string is what will get added under the <connectionString> section in the web.config file. SQL Data source further on uses this connection string to connection to perform CRUD operations using the controls like grid view etc.

Having said that once the connectionString is stored in web,.config file (notice that it has complete details of the name of the SQL server, and other parameters), you can programatically retrive the connection string using the syntax

ConfigurationManager.ConnectionStrings["NW"].ConnectionString;

Note in the above "NW" is the name attribute of the connection string. This is the name for the connection string that you would have provided when you had originally used SQLDataSource to create the connection. You can use the name inside the web.config file also.

Hope the helps

VJ

No comments:

Post a Comment