change data source for sql server database for any computer wpf c# - connection-string

I think my question is probably amateur but i don't know about it & can't find any answer about it .
I Create a program in wpf using c#
It ran success on my PC , but when install it on the other PCs , it return xamlparse error & i think its about my connection string.my database is sqlserver ver. 12.
it's myconnectionstring
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database1.mdf;Integrated Security=True;Connect Timeout=30;
i think it's about datasource
please help me
thx

Related

SQL Server connection failing with LinqToSQL but working with EF 6

I have an application (.NET WPF LinqtoSQL) that works when I connect to a local database. When I changed to a database on a different server I get an error (SQL Server Instance not found error 26).
The solutions to this error are all based on the server, firewall, and making sure SQL Server Browser is up and running, none of which I can do because I have no rights on the server.
But I created a small test application using WPF and EF (ADO.NET) that successfully connects to the exact same database (and table). I have no clue what might be going on, but I am not sure I want to re-write the application using EF (at least right now).
Does anyone understand the difference between the framesworks' connection method to point me to a possible solution for the LinqToSQL version beyond waiting for the IT guys to "fix" the server?
Given the revelation above that EF and L2S use the same connection class I figured a new project that points to the new server would fix my issue. And it did:
I created a new project, added a new L2S item, and then copied in all of my old projects views/ viewmodels/ etc. and it runs just fine.
I thought I could simply update the connection string, as this is what I believe I have done successfully in the past, but perhaps there is something else had to be set somewhere in the project settings or generated DataContext code to the new server. If anyone knows what that is please answer and I'll accept it.

VBScript Error Trying to disable dynamic port in SQL Server

I've been trying to automate disabling dynamic ports in a new installation of SQL Server 2012 and setting a static TCP port. I can do this without an issue from the SQL Configuration Manager, but getting a script to do this is giving me more trouble. Luckily, I found someone that was looking to do the exact same thing here: MSDN Forums.
The code I'm using is the following:
Private Function setProperty ( ByVal path, ByVal value )
Set obj = GetObject(path)
errornumber = obj.SetStringValue(value)
If Not errornumber = 0 Then
WScript.Quit(errornumber)
End If
End Function
Set args = WScript.Arguments
If Not args.Count = 1 Then
WScript.Echo "ERROR: Invalid arguments"
WScript.Echo "Usage: cscript " & WScript.ScriptName & " "
WScript.Quit(255)
End If
' set TCP/IP port of SQLServer instance 'SQLSERVER_MATRIX'
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpPort',PropertyType=1,ProtocolName='Tcp'", args(0)
' switch off dynamic ports
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpDynamicPorts',PropertyType=1,ProtocolName='Tcp'", ""
I try running it as suggested on the site with
cscript.exe //nologo set_port_property.vbs
and get the error:
set_port_property.vbs(1,1) (null): 0x8004100E
So that's giving me a namespace error and this is where I'm stuck. It doesn't look like anyone else is having issues with this file as I've found it in multiple places, but I'm trying this on a Windows 10 computer with SQL Server 2012 and everything I found was using 2008 and at most Windows 8. There's a Scriptomatic 2.0 tool that may help, but the link on Microsoft's page is broken so I don't know where to go from here.
The error code as you point out is
WBEM_E_INVALID_NAMESPACE (0x8004100E)
The specified namespace did not exist on the server.
Which is pretty self explanatory, basically the namespace being passed is not recognised for whatever reason, usually it's just incorrectly typed but as you have already mentioned others are using this script without issue.
Couple of suggestions
This likely points to the machine, the first thing I would try is running the script on another machine to see if it can be isolated to this machine alone.
You may also want to test the health of the WMI installation using the in-built tools provided in Windows. The wbemtest.exe tool is a great little tool for testing connection to and query WMI respositories.
Stumbled on the Answer
In the process of answering this question think I may have stumbled on the answer.
Tried suggestion 2. myself to test connecting to
root\microsoft\sqlserver\computermanagement
but failed with the same error using wbemtest.exe but found I could connect to
root\microsoft\sqlserver
After a quick google found the MSDN documentation that describes"How to: Access WMI Provider for Configuration Management using WQL" pointed me in the right direction.
You see the namespaces are different for later versions of SQL Server.
SQL Server 2005
root\Microsoft\SqlServer\ComputerManagement
SQL Server 2008 R2
root\Microsoft\SqlServer\ComputerManagement10
SQL Server 2012, SQL Server 2014, SQL Server 2016#
root\Microsoft\SqlServer\ComputerManagement11
# - Possibly subject to change
After connecting to
root\Microsoft\SqlServer\ComputerManagement11
using wbemtest.exe I no longer received the error and was able to browse classes and instances.
With that in mind changing your namespace in the code should fix the issue.
' set TCP/IP port of SQLServer instance 'SQLSERVER_MATRIX'
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement11:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpPort',PropertyType=1,ProtocolName='Tcp'", args(0)
' switch off dynamic ports
setProperty "WINMGMTS:\\.\root\Microsoft\SqlServer\ComputerManagement11:ServerNetworkProtocolProperty.InstanceName='SQLSERVER_MATRIX',IPAddressName='IPAll',PropertyName='TcpDynamicPorts',PropertyType=1,ProtocolName='Tcp'", ""
In fact at the very bottom of that thread on MSDN someone even hints at this but for SQL Server 2008
Goozak posted in MSDN Forums - silent install with fixed tcp port
Date: Wednesday, March 17, 2010 3:13 PM
"know this is an old thread, but since this is the post I found that helped me solve my problem, I just want to add that for SQL Server 2008 Express, you need to use ComputerManagement10 :ServerNetworkProtocolProperty..."

Error deploying my visual studio project in another computer

I had a deployed visual project 2010 connected to sql and I had installed it in another computer but the database can't connect to the final project. I want to install it in other computers that will be connected to database. I think I have a problem in my connection:
Dim con As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=enrollment")
The information provided at this link will provide you with a good idea of how to manage connection strings in VS. The problem with your SqlConnection object is that your data source is still listed as 'localhost'. You need to change this to point to the location of your database.
Ideally the application should have a user friendly way of specifiying the settings for the connection, this will make connecting from different locations far easier and makes your application more portable.
I think this example here will help you

SQL Server connectionStringName needed WebSecurity

I'm really sorry but I think I can't figure out a very trivial thing. I am trying to get started with WebSecurity (asp.net MVC), but the initial method asks for a connection string.
I have a SQL Server 2012 edition installed.
Created a database "Users"
Where can I find the connection string?
(I did manage to create a database + tables using EF code first, so I know things are installed properly)
You'll need to get the specifics (userid, password and servername) for your install, but this website can help with the syntax/format:
http://www.connectionstrings.com/sql-server-2012

How to configure ODBC Data Source Administrator (DSA) for MS Access db?

I ultimately want to query an existing MS-Access database (say, contacts.mdb) from a Lazarus program I will write.
It appears that configuring a User DSN is the first step.
In the ODBC DSA, I am stuck at Adding a driver for MS-Access databases. What do I need to download for this?
OK, I'm starting over from scratch. Please bear with me.
I'm now trying to use the Lazarus example given at wiki.lazarus.freepascal.org/MS_Access.
Following the Instruction given as "Goto your [Data sources (ODBC)] at the control panel administrative tools..." I run /usr/bin/ODBCConfig and get an error which says "Invalid window handle." Clicking OK closes without anything.
Does this mean I've gotten everything so FUBAR that's it's hopeless?
If your program is written in PHP you can use php5-odbc for access any odbc source, like mssql server or access databases.
This post http://phplens.com/phpeverywhere/node/view/9 illustrate you all the necessary step.
Thsi might be the thing you need
http://www.easysoft.com/products/data_access/odbc-access-driver/
I think it should be enough to put something like the following in ~/.odbc.ini:
[Contacts]
Description = The Contacts Database
Driver = /usr/lib/libmdbodbc.so
Database = /home/dkjmusic/data/contacts.mdb
Of course you need an MDB ODBC driver (e.g. libmdbodbc Install libmdbodbc http://bit.ly/software-small) to be installed

Resources