This is my first time to post here. I think this place is very good because I can force myself to record the difficulties and solutions in a timely manner. I have done a lot of things before, but I have forgotten them after a long time. Writing it down can be regarded as an encouragement to myself. Of course I hope it can be of some help to everyone, but after all, my abilities are limited, so I have to ask for more advice from experts.
After installing vs2005, if you choose to install SqlExpress, everything is configured by default. Drag the "login control" and you can use it. But this seems not enough, ok, install SqlServer. It took a lot of effort to install it first. , I won’t go into too much detail here. So how should I configure it?
I also found it on msdn, see the code below. Add a section in web.config to connect to the database.
1 <configuration>
2 <connectionStrings>
3 <remove name="LocalSqlServer"/>
4 <add name="LocalSqlServer"
5 connectionString="Data Source=localhost;
6 Initial Catalog=appservicesdb;
7 Integrated Security=True"
8 providerName="System.Data.SqlClient"/>
9 </connectionStrings>
10 </configuration>
Here are a few words, the seventh line, if it is based on window verification, write it like this, but (Windows 2003) users need to set the user, otherwise it will not pass. I use user= for this code. ***, pwd=***, because I need to transplant later, the web and sql servers are separated, and I prefer the latter. What
I am very confused about is the third sentence, I don’t know why remove is used, this is explained on msdn :
1 <connectionStrings>
2 <add />Adds a connection string in the form of name/value pairs to the connection string collection.
3 <clear />Removes all references to inherited connection strings, allowing only those added by the current add element.
4 <remove />Removes the reference to the inherited connection string from the connection string collection.
5 </connectionStrings>
6
7
I don’t know if you have noticed, but if I remove the word remove, an error will be reported. After a lot of trouble, in fact, the <connectionStrings /> paragraph is equivalent to overloading. Think about it, why can you connect by default in SqlExpress? It should be configured somewhere. I have been exposed to Unix and Linux before, and the biggest impression is their configuration files. Everything needs to be configured by you, and once you configure it, the structure will be very clear, and everything is configured using text. I'm always a little confused when using Microsoft stuff, and I don't know how they are connected. Now Microsoft feels that configuration files are much better. I'm a little off topic, so come back soon. So I always feel like I’m looking for a configuration file, but I’ve actually found it. There is a piece of code in machine.config as follows:
1 <connectionStrings>
2 <add
3 name="LocalSqlServer"
4 connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
5 providerName="System.Data.SqlClient"
6 />
7 </connectionStrings>
8
Found the source, this sentence is at work. When you start the page you edited, your web.config file will be called first. When it is found that there is no configuration in your web.config, go to machine.config to find it. So there is the remove statement above. In fact, not only that, but LocalSqlServer cannot be changed, because the later provider in machine.config also calls LocalSqlServer. If you are interested, you can take a look, but I won’t go into details here.
Finally, I need to remind everyone that it is best not to change machine.config. It is very likely that if you change something, your machine will have a big problem.
Source: wendy BLOG
http://wendy980622.cnblogs.com/archive/2006/03/09/346198.html