c# connect to sql using attachdb
来源:互联网 发布:homebrew mysql 密码 编辑:程序博客网 时间:2024/05/22 04:55
a. database
App_Data/test.mdf
b. webconfig
<connectionStrings>
<add name="test1Con" connectionString="Data Source=.\SQLEXPRESS;
AttachDBFilename=|DataDirectory|test.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
c. c#
protected void Button_Click(object sender, EventArgs e) { SqlConnection con=null; SqlCommand cmd; SqlDataReader dr; try { string strcon = ConfigurationManager.ConnectionStrings["test1Con"].ToString(); con = new SqlConnection(strcon); cmd = con.CreateCommand(); cmd.CommandText = "select * from a"; con.Open(); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (dr.Read()) { string s = Convert.ToString(dr[0]); } } catch (Exception ex) { throw ex; } finally { con.Close(); }}
d. config
application pool
->create new application pool for .net framework v2.0
->set the name of the new application name to any name
->right click and choose advance settings
->set process model to Integrated
->set identification to localsystem
->set your website to this application pool
->restart you webapplication and it will be ok
e. error will occur without the config above
Please make sure the user has a local user profile on the computer.
<finish>
- c# connect to sql using attachdb
- How to Connect to MySQL Using C#
- Using DBI to connect to a Microsoft SQL server
- SQL: How to get a series of dates in sql using connect by
- using DTP to connect to MySQL
- Using WebDav to connect to Plone ZODB
- 7 Simple Steps to Connect SQL Server Using WCF from SilverLight
- Connect to Dababase using JDBC in JSP
- connect to Gmail Imap using javamail
- SQL Server connect to MySQL
- SQL Developer Connect to MySQL
- How to connect to another database using sqlplus?
- Using Scala with JDBC to connect to MySQL
- Using IPv6 to connect computer in dorm from our laboratory
- How to connect WN111 & WNR834Bv2 using WPS PIN method?
- Can't connect to X11 window server using ':0.0'
- mysqlnd cannot connect to MySQL 4.1+ using old authentication
- Java connect to Oracle DB using two method
- 《Java平台体系》——第二章 JVM——JVM实现:内存管理和垃圾回收
- android之Fragment(官网资料翻译)
- phonics-16
- Enabling High Performance Data Transfers
- 动态任务创建与实时任务创建与管理模块
- c# connect to sql using attachdb
- HDU 1667 The Rotation Game IDA*搜索
- 设置Windows任务计划,以“每小时”重复
- 为cocos2d-x移植贪食蛇游戏
- 安全方面的文章+VC知识库
- winform打印datatable
- 雷雨交加的星期五
- Android中截图(surfaceView)
- 13日,7月 2012 -- 计划依旧没有执行 / 买了个域名 / Drupal Alter / 继续定计划