In your homework you spent a lot of time creating the database and the stored pr
ID: 3853883 • Letter: I
Question
In your homework you spent a lot of time creating the database and the stored procedures, writing queries. You created your database from the Windows Explorer file in the App_Data folder, and then connected to it locally using the Server Explorer. This interface is the same if you are using an express or enterprise version of SQL Server, but also the same for Microsoft Access. We don't use Access for internet databases, but it can be useful to local one-computer web applications where the cost of SQL Server would be prohibited.
So, the challenge this week was learning physically how to create the databases, tables and populate the tables. You learned about relationships between tables. But again, you worked locally. When we are on a web page, the web server and database server can be on separate physical or virtual servers, even across the country! So we have to be able to get the web application to connect to the database. That's where the connection string comes in. It's like giving someone directions.
When you created your project, Visual Studio created a database in App_Data and stored the connection string in the web.config file as shown. It is used to manage the users who log into the web site. You can't see the database in the folder, but it's there. Use Windows Explorer to locate it. It's named aspnet-[projectname]-[somenumber].mdf and a log file is named aspnet-[projectname]-[matchingnumber]_log.ldf. In the actual file, you don't split the string across lines!
This is where can get tricky. You need to create your own connection string. So you need to know what each of the parts of the connection string mean.
The connection string needs to know the location where the SQL Server resides, and that's usually adomain name or IP address. This may vary!
Then you need to know who you are talking to, and that is the name of the server. This is the initial catalog.
The AttachDbFilename shows the name of the file and the path. Since we want to move the application we use a variable that will represent the path, |DataDirectory|. It actually maps to the App_Data folder.
Give the connection string variable a better descriptive name than connectionString. You can't use variable names twice. Definitely don't call it connection string. Some people call it the name of the database and append SQL.
You will use Integrated Security for class. In a production server you may need to pass a username and password.
Explanation / Answer
Here we have connection string syntax with Sql Server Express:
In above connection string we have:
1) name: The name of connection string we need to define.
2)Provider Name: in order to establish a successfull connection we have to import System.Data.SqlClient and Provider names for .NET providers are implicit based on the implementing class and do not need to be specified in the connection string if we are using the .NET Provider for SQL Server (System.Data.SqlClient).
3)connectionString: The entire connection string includes:
3a)DataSource: Here the database source is the name of remote server or ip address of remote server
3b)Initial Catalog: The name of database( 128 charecters or less) which resides on remote server.
3c)Integrated Security: if integrated security false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication,Recognized values are true, false, yes, no, and sspi (strongly recommended).
3c) user id: The name of user on remote sql server
3d) password: Password for account.
Here is example of a connection string:
In aboove example Datasource can be defined in following way:
(localhost)SQLEXPRESS
192.168.43.10SQLEXPRESS