本地数据库时什么怎么找到(sql数据库地址在哪里)

本地数据库时什么怎么找到(sql数据库地址在哪里),第1张

本地数据库就是和调用程序同在一台电脑上的数据库。

远程数据库,需要网络远程链接,于调用程序不在同一台电脑上。

你是要找到本地数据库的文件?还是要链接本地数据库?

如果是程序要链接数据库,一般是需要数据库地址,数据库名,数据库帐号,数据库密码

本地的就填写localhost为数据库地址,远程的就填写IP地址

如果需要找到本地的数据库文件,需要查看数据库的设置,得到路径。

创建应用 UI

若使用 Windows Phone SDK,则使用 Windows Phone 应用 模板创建新项目。

创建好项目后,从 “项目” 菜单中选择 “添加现有项”。该 *** 作将打开“添加现有项”菜单,我们可以从中选择用于删除待办事项的图标

在“添加现有项”窗口中,导航到以下路径并选择命名为 appbardeleterestpng 的图标。该图标设计用于深色背景并且颜色为白色;该图标在“添加现有项”窗口的白色背景中可能显示为空白。

C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v80\Icons\dark

注意:

此步骤假定采用的是以默认方式安装的 Visual Studio。如果您将其安装在其他位置,则在相应的位置查找图标。

单击“添加”。该 *** 作将图标添加到解决方案资源管理器中的列表。

在“解决方案资源管理器”中,右键单击图标并设置文件属性,以便以“内容”的形式生成图标并且始终复制到输出目录(“始终复制”)。

在 MainPagexaml 上,删除名为 LayoutRoot 的 Grid 的 XAML 代码,并替换为以下代码。

XAML

<!--LayoutRoot is the root grid where all page content is placed-->

<Grid x:Name="LayoutRoot" Background="Transparent">

<GridRowDefinitions>

<RowDefinition Height="Auto"/>

<RowDefinition Height=""/>

</GridRowDefinitions>

<!--TitlePanel contains the name of the application and page title-->

<StackPanel x:Name="TitlePanel" GridRow="0" Margin="12,17,0,28">

<TextBlock x:Name="ApplicationTitle" Text="LOCAL DATABASE EXAMPLE" Style="{StaticResource PhoneTextNormalStyle}"/>

<TextBlock x:Name="PageTitle" Text="to-do list" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

</StackPanel>

<!--ContentPanel - place additional content here-->

<Grid x:Name="ContentPanel" GridRow="1" Margin="12,0,12,0">

<GridRowDefinitions>

<RowDefinition Height="Auto" />

<RowDefinition Height="Auto" />

</GridRowDefinitions>

<!-- Bind the list box to the observable collection -->

<ListBox x:Name="toDoItemsListBox" ItemsSource="{Binding ToDoItems}"

GridRow="0" Margin="12, 0, 12, 0" Width="440">

<ListBoxItemTemplate>

<DataTemplate>

<Grid HorizontalAlignment="Stretch" Width="440">

<GridColumnDefinitions>

<ColumnDefinition Width="50" />

<ColumnDefinition Width="" />

<ColumnDefinition Width="100" />

</GridColumnDefinitions>

<CheckBox

IsChecked="{Binding IsComplete, Mode=TwoWay}"

GridColumn="0"

VerticalAlignment="Center"/>

<TextBlock

Text="{Binding ItemName}"

FontSize="{StaticResource PhoneFontSizeLarge}"

GridColumn="1"

VerticalAlignment="Center"/>

<Button

GridColumn="2"

x:Name="deleteTaskButton"

BorderThickness="0"

Margin="0"

Click="deleteTaskButton_Click">

<Image Source="appbardeleterestpng"/>

</Button>

</Grid>

</DataTemplate>

</ListBoxItemTemplate>

</ListBox>

<Grid GridRow="1">

<GridColumnDefinitions>

<ColumnDefinition Width="" />

<ColumnDefinition Width="Auto" />

</GridColumnDefinitions>

<TextBox

x:Name="newToDoTextBox"

GridColumn="0"

Text="add new task"

FontFamily="{StaticResource PhoneFontFamilyLight}"

GotFocus="newToDoTextBox_GotFocus"/>

<Button

Content="add"

GridColumn="1"

x:Name="newToDoAddButton"

Click="newToDoAddButton_Click"/>

</Grid>

</Grid>

</Grid>

XAML 代码将向应用添加两个 Grid 元素。其中一个 Grid 包含显示待办事项的 toDoItemsListBox。随着绑定到列表的待办事项越多,ListBox 的尺寸将有所增加,逐渐将第二个 Grid 推向屏幕下方。另一个 Grid 元素包含用来输入新待办事项的 newToDoTextBox 和Button。

生成数据上下文

在本节中,将指定一个确定数据库架构的对象模型并创建数据上下文。

生成数据上下文

打开主页的代码隐藏文件(名为 MainPagexamlcs)。该页面将包含大部分应用逻辑。为了简便起见,该应用将特意保留在一个页面中。实际应用通常会使用模型-视图-视图模型 (MVVM) 编程模式。有关更多信息,请参见实现面向 Windows Phone 8 的模型视图查看模型模式。

该应用需要引用 Windows Phone 的 LINQ to SQL 程序集。从“项目”菜单中,单击“添加引用”,从“程序集/框架”列表中选择“SystemDataLinq”,然后单击“确定”。

注意:

当面向 Windows Phone 8 时,使用 Windows Phone 应用 模板的新应用自动引用该程序集。

在页面顶部添加以下指令。

C#

using SystemDataLinq;

using SystemDataLinqMapping;

using SystemComponentModel;

using SystemCollectionsObjectModel;

在 MainPage 类下,添加以下代码。这是一个名为 ToDoItem 的实体类,表示本地数据库中应用的数据库表。该类实现INotifyPropertyChanged 以进行更改跟踪。实现 INotifyPropertyChanging 有助于限制与更改跟踪相关的内存占用。表属性 [Table] 指示 LINQ to SQL 运行时将类映射到本地数据库表。

C#

[Table]

public class ToDoItem : INotifyPropertyChanged, INotifyPropertyChanging

{

// Define ID: private field, public property and database column

private int _toDoItemId;

[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSyncOnInsert)]

public int ToDoItemId

{

get

{

return _toDoItemId;

}

set

{

if (_toDoItemId != value)

{

NotifyPropertyChanging("ToDoItemId");

_toDoItemId = value;

NotifyPropertyChanged("ToDoItemId");

}

}

}

// Define item name: private field, public property and database column

private string _itemName;

[Column]

public string ItemName

{

get

{

return _itemName;

}

set

{

if (_itemName != value)

{

NotifyPropertyChanging("ItemName");

_itemName = value;

NotifyPropertyChanged("ItemName");

}

}

}

// Define completion value: private field, public property and database column

private bool _isComplete;

[Column]

public bool IsComplete

{

get

{

return _isComplete;

}

set

{

if (_isComplete != value)

{

NotifyPropertyChanging("IsComplete");

_isComplete = value;

NotifyPropertyChanged("IsComplete");

}

}

}

// Version column aids update performance

[Column(IsVersion = true)]

private Binary _version;

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

// Used to notify the page that a data context property changed

private void NotifyPropertyChanged(string propertyName)

{

if (PropertyChanged != null)

{

PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

}

}

#endregion

#region INotifyPropertyChanging Members

public event PropertyChangingEventHandler PropertyChanging;

// Used to notify the data context that a data context property is about to change

private void NotifyPropertyChanging(string propertyName)

{

if (PropertyChanging != null)

{

PropertyChanging(this, new PropertyChangingEventArgs(propertyName));

}

}

#endregion

}

ToDoItem 类具有三个公共属性,分别与三个数据库列相对应:

重要说明:

为了限制更改跟踪所需的内存占用,请始终对数据上下文中的对象实现 INotifyPropertyChanging 接口。

ToDoItemId:由数据库自动填充的标识符列。同时,该列也是一个主键,系统会为其自动创建数据库索引。这些以及其他设置均使用在属性语法上方编写的 LINQ to SQL Column 映射属性指定。

ItemName:存储待办事项文本的列。

IsComplete:存储待办事项完成状态的列。

在 MainPage 类下,添加以下代码。这是一个名为 ToDoDataContext 的类。该类继承自 DataContext,被称为数据上下文。最重要的是,该代码将调用基构造函数并声明名为 ToDoItems 的数据库表。

C#

public class ToDoDataContext : DataContext

{

// Specify the connection string as a static, used in main page and appxaml

public static string DBConnectionString = "Data Source=isostore:/ToDosdf";

// Pass the connection string to the base class

public ToDoDataContext(string connectionString)

: base(connectionString)

{ }

// Specify a single table for the to-do items

public Table<ToDoItem> ToDoItems;

}

注意:

不要求数据库连接字符串必须为静态字段,该特定示例中仅为方便使用而要求。有关连接字符串的更多信息,请参阅 Windows Phone 8 的本地数据库连接字符串。

SQL Server 2005允许远程连接的配置说明

>

mysql修改编码,linux/Mac/Unix/通用 修改mysql的编码需要用到myslq的配置文件,该文件在/etc/mycnf,mac用户默认是没有这个文件的,可以到mysql的安装目录/support-files中找任意一个my-cnf拷贝到/ect中,注意复制过来改名字为mycnf! 然后: 在[client]下面加default-character-set = utf8 然后在[mysqld]下面加入以下三行: default-storage-engine = INNODB character-set-server = utf8 collation-server = utf8_general_ci 以上能保证程序时utf_8的编码,但是可能还是有问题,不能插入中文。 2查看数据库的编码,在workbench中重修改成utf-8-general-ci,可能还是不行。 3看具体的数据表,看varchar()的collection属性,一般是latin1,把这个也修改成utf-8-general-ci,完美解决问题。

1这种情况显然是有实例名的哦。用ip连接只要设置Server name 为ip/SQLEXPRESS就OK了。

2如果不是实例名的问题,就按照下列的 *** 作来处理。

首先使用SQL Server 2005外围应用配置器, 服务和连接的外围应用配置器——Database Engine——远程连接——选择本地连接和远程连接——同时使用TCP/IP和named pipes(B)——确定,然后重新启动 SQL Server (SQLEXPRESS)服务。

3请参考下列图 *** 作:

检查数据库的属性——Security 选择SQL Server and Windows Authentication mode

以上就是关于本地数据库时什么怎么找到(sql数据库地址在哪里)全部的内容,包括:本地数据库时什么怎么找到(sql数据库地址在哪里)、如何为 Windows Phone 8 创建基本的本地数据库应用、网站数据库连接本地数据库怎么设置等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9565057.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存