立刻结贴:连接字符串问题
我如果连接SqlExpress中的内置的Northwind数据库,可以这样:
SqlConnection conn;
conn = new SqlConnection( "Data Source = .\\SQLExpress;Initial Catalog = Northwind; Integrated Security = SSPI ");
但我现在要连自己的数据库,比如
E:\WEB\PWS网站\APP_DATA\ASPNETDB.MDF;
这个的话,我的连接字符串应该怎么写呢???把它加入到我的sqlserver服务器里,也是这么个地址加名称,我直接写到连接字符串里,就出错啊~~~~
求救~~得到答案就结贴!
------解决方案--------------------沙发,帮忙顶
------解决方案--------------------server=localhost;user=数据库用户名;pwd=数据库密码;initial catalog=数据库名称
------解决方案--------------------LS正解.
------解决方案-------------------- "Data Source=127.0.0.1;Initial Catalog=ASPNETDB;Integrated Security=True "
------解决方案--------------------data source=.;database=数据库名称;uid=sa;password=
------解决方案--------------------SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings[ "ConnectingString "]);
<appSettings>
<add key= "ConnectingString " value= "Data Source=localhost;user id=sa;password=;initial catalog=lydoor "/>
</appSettings>
------解决方案--------------------SqlConnection conn;
conn = new SqlConnection( "server=127.0.0.1;uid=数据库用户名;pwd=数据库密码;DataBase=数据库 ");
------解决方案-------------------- <appSettings>
<!-- 数据库连接字符串 -->
<add key= "ConnString " value= "Data Source=(local);database=数据库名;UID=sa;Password=sa;Persist Security Info=True; " />
</appSettings>
------解决方案--------------------SqlConnection conn;
conn = new SqlConnection( "server=.;user=sa;pwd=;DataBase=数据库名称 ");
------解决方案--------------------如果是SQL2005直接如下应该是可以的吧:
SqlConnection conn;
conn = new SqlConnection( "Data Source = .\\SQLExpress;Initial Catalog = ASPNETDB; Integrated Security = SSPI ");
------解决方案-------------------- <connectionStrings>
<add name= "ConnectionString " connectionString= "Data Source =(local);uid=用户名;pwd=数据库密码;database=数据库名称 ">
</connectionStrings>
sqlconnection conn=new sqlconnection(configurationmanager.connectionstrings[ "ConnectionStirng "].connectionstring);