Network error on powershell SQL job step - sql

This is partially my code and partially from others help here on stack overflow.
$excelFile = "C:\ExcelTest\Test.csv"
$functionDirectory = "C:\foldername"
$csv = Import-csv $excelFile -Header FileName
Import-Module sqlps
foreach ($line in $csv)
{
if(test-path -path ($functionDirectory + "\" + $line.FileName))
{
invoke-sqlcmd -inputfile "C:\foldername\filename.sql" -serverinstance "servername\instancename" -database "databasename"
}
}
I had to remove the specific serverinstance / servername for privacy but I've checked both of those several times and I don't think that is where the issue is. I keep getting the error
A network related or instance specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections.
I have double checked server / instance name which I got from the server by running
select ##servername + '\' + ##SERVICENAME
nd the database name obviously was easy to get. I have double checked that the server is set up for remote connection (even though this is a database that is local on my laptop and not a remote server currently).
I'm kinda at a loss for what else to check for.
I had read you should look at firewall settings but I don't think those should make a difference when its a local server on my machine.
I'm still somewhat new with SQL and powershell so I apologize for any blatant syntax or formatting errors (please point out so I can correct them). Any help would be appreciated.

Turns out I needed to remove the instance name and just use the server name.

Related

bWAPP on my live webserver is tossing me an sql error

I am trying to put bWAPP on my spare webserver for me and my friends to use.
It's locked by a password and stuff, so only people who know it can use it.
Here's the configuration I have right now.
$db_server = "atroxis.net";
$db_username = "ethereal_atrox";
$db_password = "(redacted)";
$db_name = "ethereal_bwapp";
The password is right, I just redacted it.
I keep getting this SQL error.
Connection failed: Access denied for user 'ethereal_atrox'#'51.38.85.24' (using password: YES)
Anyone have any ideas?
Try to put:
$db_server = "localhost";
and reload apache.
If it doesn't work, verify the file connect.php and change myql_ for mysqli_

Powershell SMO Can't Connect

I'm having an issue connecting to a SQL Server using SMO when using a ServerConnection. For the last few months this has been working, but now failing. Here is a snippet of the script:
$svrname = "Server"
#Establish Server connection
Write-ColorOutput "Establishing SQL Server Connection to $svrName" "White"
$mysvrConn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$mysvrConn.ServerInstance=$svrName
$mysvrConn.LoginSecure = $false
$mysvrConn.Login = "Admin"
$mysvrConn.Password = "Password"
$svr = new-object 'Microsoft.SqlServer.Management.SMO.Server' $mysvrConn
However, the following works.
$svrname = "Server"
$svr = new-object ('Microsoft.SQLServer.Management.SMO.Server') $svrname
And the assemblies:
Write-ColorOutput "Loading assemblies" "White"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SQLServer.Smo") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null
You almost certainly have permission issues with your SQL login. You are either using the wrong password, or the login does not have the proper creds.
Embarrassingly, when I had this issue, it turned out to be that I had entered the login password incorrectly.
I had expected a specific error stating the login failed. Instead it was the more generic: Failed to connect to server localhost., which threw me off.
Like you, I ran a test with the $LoginSecure = $True which worked, telling me that the connection to the server was fine. Only then did I spot my typo and was on my way to SMO bliss.

How to identify a weblogic admin server from its managed server?

The managed server is a remote machine. Given a managed server hostname or ip how can its admin Server be identified.
You can use WLST for this.
>cd %ORACLE_HOME%\oracle_common\common\bin
>wlst
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline> connect('weblogic', 'dev_password', 't3://dev_host:7011')
Connecting to t3://dev_host:7011 with userid weblogic ...
Successfully connected to managed Server 'soa_server1' that belongs to domain 'dev_domain'.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
wls:/dev_domain/serverConfig> serverRuntime()
Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)
wls:/dev_domain/serverRuntime> print cmo.adminServerHost
dev_host
wls:/dev_domain/serverRuntime> print cmo.adminServerListenPort
7001
wls:/dev_domain/serverRuntime>
Where dev_host:7011 is a managed server and dev_host:7001 is the admin server.
In addition you can look it up with pure java code, JMX, after - connecting to the managed server like:
String serverName = System.getProperty("weblogic.Name");
ObjectName serverRuntime = new ObjectName("com.bea:Name=" + serverName + ",Type=ServerRuntime");
Object adminHostName = server.getAttribute( serverRuntime, "AdminServerHost" );
Object adminPort = server.getAttribute( serverRuntime, "AdminServerListenPort" );
response.getWriter().write("Admin server host and port " + adminHostName + ":" + adminPort );

Importing 1GO SQL File => ERROR 2013 (HY000) at line 23: Lost connection to MySQL server during query

Ive got to import 1go of sql data, i raised up the max_allowed_packet to 1100M to be sure.
So i use :
My query
mysql -u root -p -D mainbase < GeoPC_WO.sql
But 1 minute later it stops during the process and i get this error :
**ERROR 2013 (HY000) at line 23: Lost connection to MySQL server during query
**Lost connection to MySQL server during query****
Possible that you have some large insert statements that are bigger than you max size. Check your /etc/mysql/my.cnf file or wherever it is. Cannot remember what the default is - but setting it to something large like below may help.
This is one option
[mysqld]
max_allowed_packet = 16M
And maybe the other way
[mysqldump]
max_allowed_packet = 16M
I had exactly the same problem. After 1 hour of struggling I resolved this by setting
net_write_timeout
to a higher value (in my situation it's 300)
In my case the problem ("Lost connection to MySQL Server during query") was in a corrupted dump file or in the misbehaving HDDs:
First, I made a dump on the main server and then copied that dump to the replication server. But it seems the replication server had some problems with its HDDs and the dump became corrupted, i.e. MD5 of the original dump file on the main server was different from MD5 of the dump copy on the replication server.
You can try with this:
First:
sudo /etc/init.d/mysql stop
Then you should edit this file:
sudo vi /etc/mysql/my.cnf
Add the following line to the [mysqld] section:
innodb_force_recovery = 4
Finally:
sudo /etc/init.d/mysql start
(innodb_force_recovery force the InnoDB storage engine to start. The value 4 mean your data files can be corrupted. For more information you can visit: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html)
Greetings.
In my case it was because of the lack of RAM, I tried to import a 90MB zipped sql file to a 1GB RAM vps server and the error 2013 keep occured until I switched down the httpd service to release some memory and run the import command again and it was successful then.
I am getting same error when import SQL file:
ERROR 2013 (HY000) at line 23: Lost connection to MySQL server during
query Lost connection to MySQL server during query
I have solved by using this solution:
First of all, stop the XAMPP/Wamp and then kindly open this file xampp\mysql\bin\my.ini
Increase size as per your requirement
max_allowed_packet=60M
And then restart your XAMPP/Wamp.
NOTE: For Windows, you can find the file in the C:\xampp\mysql\bin\my.ini Folder (Windows) or in the etc-Folder (within the xampp-Folder).
Very important Note: "Close your Command Prompt And Restart Again" (It's very important because if you didn't restart your command prompt then changes will not be reflected.)

Access SQL - WMI Namespaces from Remote Machine

i am playing with Powershell and SQL WMI events and i am wondering if i can do this stuff remotely from the admin notebook:
I'd like to query the "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" namespace:
On SQLServer directly:
get-wmiobject -list -namespace "root\Microsoft\SqlServer" >> Works!
get-wmiobject -list -namespace "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" >> Works !
On my Adminmachine:
get-wmiobject -list -namespace "root\Microsoft\SqlServer" >> Works!
get-wmiobject -list -namespace "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER" >> Error: Invalid Namespace.
Is there a trick to get this running? Do i have to additional install sth?
I am still on SQL 2005.
Thanks!
Use the computername name parameter.
get-wmiobject -computername Z002 -list -namespace "root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER"
Also keep in mind MSSQLSERVER is only available if the server has a default instance. If the server uses a named instance you'll need to specify the instance name instead of MSSQLSERVER.
Posted - 05/05/2012 : 08:25:20
Hi All,
We've developed a free WMI CLR assembly to execute WMI queries in SQL.
e.g. This will return mount point and drive space
DECLARE #XmlData Xml
--Obtain Windows Services
select #XmlData=dbo.GetWMI('\\SQL2008WIN2008\root\cimv2', --Machine and WMI class
NULL, --UserName, leave NULL to use current
NULL, --Password, leave NULL to use current
'select * from win32_volume' --WMI Class
)
SELECT
tbl.A.value('(DeviceID)[1]','VARCHAR(100)') as DeviceID,
tbl.A.value('(Name)[1]','VARCHAR(200)') as Name,
tbl.A.value('(DriveType)[1]','int') as DriveType,
ISNULL(tbl.A.value('(DriveLetter)[1]','VARCHAR(10)'),'MountPoint') as DriveLetter,
tbl.A.value('(FreeSpace)[1]','bigint')/1024/1024 as FreeSpaceMbytes
FROM #XmlData.nodes('/WMI/Data') tbl(A)
Have a look at http://micatio.com/sqlwmi.aspx