ADO.NET連接SQL2000
2015-09-07 10:02
246 查看
EF4.0連接SQL2000
一、建立一個空的Web運用程式
二、添加新建項目,選擇ADO.NET實體數據模型,改名為MyModel.edmx,
三、選擇空模型,完成
四、將MyModel.edmx以記事本的形式打開,並將用(http://www.skonet.com/uploadedFiles/Code/BaseEntityModel.edmx.xml )xml文件內容替換。並Ctrl+F把所有%DB_NAME% 替换成MyModel,共6处替换,替换完成后保存关闭该页,不关闭后面可能会出问题。
五、在项目中新建一个配置文件web.config,把以下配置节复制到web.config,
<connectionStrings>
<add name="%DB_NAME%Entities" connectionString="metadata=res://*/%DB_NAME%.csdl|res://*/%DB_NAME%.ssdl|res://*/%DB_NAME%.msl;provider=System.Data.SqlClient;providerconnection string="Data Source=%DB_HOST_NAME%;InitialCatalog=%DB_NAME%;Persist Security
Info=True;UserID=%DB_USER%;Password=%DB_USER_PWD%;MultipleActiveResultSets=False"" providerName="System.Data.EntityClient" />
</connectionStrings>
六、把配置中的所有%DB_NAME%替换成MyModel,共5处替换,修改%DB_HOST_NAME%为你的数据库实例名。
七.Initial Catalog=%DB_NAME% 这里的%DB_NAME% 改成你要连接的库的名稱。
八、雙擊直接打開MyModel.edmx計設視圖模式打開,右擊選擇從數據庫更新模型。
九、同樣支持添加代碼生成項
整個項目就是這樣的
XML文件
<edmx:Edmxxmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"Version="2.0">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schemaxmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"Namespace="%DB_NAME%Model.Store" Alias="Self"Provider="System.Data.SqlClient"ProviderManifestToken="2000">
<EntityContainerName="%DB_NAME%ModelStoreContainer"></EntityContainer>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schemaxmlns="http://schemas.microsoft.com/ado/2008/09/edm"Namespace="%DB_NAME%Model" Alias="Self">
<EntityContainerxmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration"xmlns:b="http://schemas.microsoft.com/ado/2009/02/edm/annotation"Name="%DB_NAME%Entities" a:TypeAccess="Public"b:LazyLoadingEnabled="true"></EntityContainer>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mappingxmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs"Space="C-S">
<EntityContainerMappingStorageEntityContainer="%DB_NAME%ModelStoreContainer"CdmEntityContainer="%DB_NAME%Entities"></EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!--
EF Designer content (DO NO2015/9/2t EDITMANUALLY BELOW HERE)
-->
<edmx:Designer>
<edmx:Connection>
<DesignerInfoPropertySetxmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
<DesignerPropertyName="MetadataArtifactProcessing"Value="EmbedInOutputAssembly"/>
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySetxmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
<DesignerPropertyName="ValidateOnBuild" Value="true"/>
<DesignerPropertyName="EnablePluralization" Value="True"/>
<DesignerPropertyName="IncludeForeignKeysInModel" Value="True"/>
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connectorpositions) -->
<edmx:Diagrams></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- c#调用COM组件
- 星外ASP.Net的安全设置相关说明
- 星外科技每天自动备份SQL2000/Mysql的工具
- C#实现把指定数据写入串口
- C#动态创建button的方法
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#通用邮件发送类分享
- C#中this的用法集锦
- C#.NET获取拨号连接的宽带连接方法
- C#异步绑定数据实现方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#生成饼形图及添加文字说明实例代码
- C#判等对象是否相等的方法汇总
- C#简单的向量用法实例教程