c# - 为什么使用 Visual Studio 2013 + Microsoft SQL Server 2017 Developer 连接数据库有空白页
问题描述
我使用 Visual Studio 2013 + Microsoft SQL Server 2017 Developer 连接数据库有空白页。
我在使用指南SQL Server 2017 开发者版用户无法连接无法解决问题,我必须真正解决连接数据库而不是空白页的答案。
当前描述的图像。
我有混合身份验证模式的设置。
我有完全打开 sa 用户的设置。
我使用 localhost:8081 并正常打开欢迎屏幕。
我将用户 sa 的密码设置为空白。
我尝试编译为示例中的代码并有空白页(没有表格过程)。
我的代码。
SQL
USE [mydatabase]
GO
/****** Object: Table [dbo].[customer] Script Date: 05/01/2012 16:44:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[customer](
[CustomerID] [varchar](4) NOT NULL,
[Name] [varchar](50) NULL,
[Email] [varchar](50) NULL,
[CountryCode] [varchar](2) NULL,
[Budget] [float] NULL,
[Used] [float] NULL,
CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED
(
[CustomerID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
INSERT INTO customer VALUES ('C001', 'Win Weerachai', 'win.weerachai@a.com', 'TH', 1000000, 600000);
INSERT INTO customer VALUES ('C002', 'John Smith', 'john.smith@a.com', 'EN', 2000000, 800000);
INSERT INTO customer VALUES ('C003', 'Jame Born', 'jame.born@a.com', 'US', 3000000, 600000);
INSERT INTO customer VALUES ('C004', 'Chalee Angel', 'chalee.angel@a.com', 'US', 4000000, 100000);
ASP.Net C#
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
SqlConnection objConn;
SqlCommand objCmd;
void Page_Load(object sender,EventArgs e)
{
String strConnString;
strConnString = "Server=localhost:8081;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
objConn = new SqlConnection(strConnString);
objConn.Open();
BindData();
}
void BindData()
{
String strSQL;
strSQL = "SELECT * FROM customer";
SqlDataReader dtReader;
objCmd = new SqlCommand(strSQL, objConn);
dtReader = objCmd.ExecuteReader();
//*** BindData to Repeater ***//
myRepeater.DataSource = dtReader;
myRepeater.DataBind();
dtReader.Close();
dtReader = null;
}
void Page_UnLoad()
{
objConn.Close();
objConn = null;
}
</script>
<html>
<head>
<title>a.com ASP.NET - SQL Server 2012</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>CustomerID</th>
<th>Name</th>
<th>Email</th>
<th>CountryCode</th>
<th>Budget</th>
<th>Used</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerID") %>'></asp:Label></td>
<td><asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label></td>
<td><asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Email") %>'></asp:Label></td>
<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CountryCode") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Budget") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblUsed" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Used") %>'></asp:Label></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#e8e8e8">
<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerID") %>'></asp:Label></td>
<td><asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label></td>
<td><asp:Label id="lblEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Email") %>'></asp:Label></td>
<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CountryCode") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Budget") %>'></asp:Label></td>
<td align="right"><asp:Label id="lblUsed" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Used") %>'></asp:Label></td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
解决方案
非常感谢您的建议。
我找到了解决问题的答案 = 在保存代码文件期间,设置字符集 UTF-8 来解决问题。
推荐阅读
- r - 如何使用 h2o.predict 预测时间序列的未来值
- javascript - 如何根据正确输入的数据在 d3.js 中缩放 y 轴
- fullcalendar - 将 Jquery Fullcalendar 事件导出到谷歌日历
- sapui5 - 在 SAPUI5 中设置初始视图
- function - 当我从函数返回一个变量时,它没有显示全部?
- javascript - 切换一个列表项而不是整个列表
- html - 给元素一个盒子以外的其他结构,例如三角形
- ios - UITableViewRowAction 在 iOS 13.0 中被弃用
- laravel - 模态关闭后无法在页面上滚动
- excel - 用户定义的函数在 vba 中工作正常,而从显示“值”错误的 excel 表调用时